From 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 20 Aug 2020 18:42:06 +0000 Subject: Add latest changes from gitlab-org/gitlab@13-3-stable-ee --- lib/gitlab/i18n/translation_entry.rb | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'lib/gitlab/i18n/translation_entry.rb') diff --git a/lib/gitlab/i18n/translation_entry.rb b/lib/gitlab/i18n/translation_entry.rb index 19c10b2e402..25a45332d27 100644 --- a/lib/gitlab/i18n/translation_entry.rb +++ b/lib/gitlab/i18n/translation_entry.rb @@ -4,12 +4,14 @@ module Gitlab module I18n class TranslationEntry PERCENT_REGEX = /(?:^|[^%])%(?!{\w*}|[a-z%])/.freeze + ANGLE_BRACKET_REGEX = /[<>]/.freeze - attr_reader :nplurals, :entry_data + attr_reader :nplurals, :entry_data, :html_allowed - def initialize(entry_data, nplurals) + def initialize(entry_data:, nplurals:, html_allowed:) @entry_data = entry_data @nplurals = nplurals + @html_allowed = html_allowed end def msgid @@ -83,8 +85,38 @@ module Gitlab string =~ PERCENT_REGEX end + def msgid_contains_potential_html? + contains_angle_brackets?(msgid) + end + + def plural_id_contains_potential_html? + contains_angle_brackets?(plural_id) + end + + def translations_contain_potential_html? + all_translations.any? { |translation| contains_angle_brackets?(translation) } + end + + def msgid_html_allowed? + html_allowed.present? + end + + def plural_id_html_allowed? + html_allowed.present? && html_allowed['plural_id'] == plural_id + end + + def translations_html_allowed? + msgid_html_allowed? && html_allowed['translations'].present? && all_translations.all? do |translation| + html_allowed['translations'].include?(translation) + end + end + private + def contains_angle_brackets?(string) + string =~ ANGLE_BRACKET_REGEX + end + def translation_entries @translation_entries ||= entry_data.fetch_values(*translation_keys) .reject(&:empty?) -- cgit v1.2.3