diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 08:27:35 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 08:27:35 +0000 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /lib/banzai/filter | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) | |
download | gitlab-ce-7e9c479f7de77702622631cff2628a9c8dcbc627.tar.gz |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'lib/banzai/filter')
-rw-r--r-- | lib/banzai/filter/emoji_filter.rb | 7 | ||||
-rw-r--r-- | lib/banzai/filter/normalize_source_filter.rb | 14 | ||||
-rw-r--r-- | lib/banzai/filter/reference_filter.rb | 6 | ||||
-rw-r--r-- | lib/banzai/filter/vulnerability_reference_filter.rb | 22 |
4 files changed, 47 insertions, 2 deletions
diff --git a/lib/banzai/filter/emoji_filter.rb b/lib/banzai/filter/emoji_filter.rb index b32fe5e8301..8952a3ff6b4 100644 --- a/lib/banzai/filter/emoji_filter.rb +++ b/lib/banzai/filter/emoji_filter.rb @@ -8,6 +8,7 @@ module Banzai # Based on HTML::Pipeline::EmojiFilter class EmojiFilter < HTML::Pipeline::Filter IGNORED_ANCESTOR_TAGS = %w(pre code tt).to_set + IGNORE_UNICODE_EMOJIS = %w(™ © ®).freeze def call doc.search(".//text()").each do |node| @@ -60,7 +61,11 @@ module Banzai # Build a regexp that matches all valid unicode emojis names. def self.emoji_unicode_pattern - @emoji_unicode_pattern ||= /(#{Gitlab::Emoji.emojis_unicodes.map { |moji| Regexp.escape(moji) }.join('|')})/ + @emoji_unicode_pattern ||= + begin + filtered_emojis = Gitlab::Emoji.emojis_unicodes - IGNORE_UNICODE_EMOJIS + /(#{filtered_emojis.map { |moji| Regexp.escape(moji) }.join('|')})/ + end end private diff --git a/lib/banzai/filter/normalize_source_filter.rb b/lib/banzai/filter/normalize_source_filter.rb new file mode 100644 index 00000000000..975cd540873 --- /dev/null +++ b/lib/banzai/filter/normalize_source_filter.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Banzai + module Filter + class NormalizeSourceFilter < HTML::Pipeline::Filter + UTF8_BOM = "\xEF\xBB\xBF" + + def call + # Remove UTF8_BOM from beginning of source text + html.delete_prefix(UTF8_BOM) + end + end + end +end diff --git a/lib/banzai/filter/reference_filter.rb b/lib/banzai/filter/reference_filter.rb index cfd4b932568..d22a0e0b504 100644 --- a/lib/banzai/filter/reference_filter.rb +++ b/lib/banzai/filter/reference_filter.rb @@ -119,7 +119,7 @@ module Banzai # Yields the link's URL and inner HTML whenever the node is a valid <a> tag. def yield_valid_link(node) - link = CGI.unescape(node.attr('href').to_s) + link = unescape_link(node.attr('href').to_s) inner_html = node.inner_html return unless link.force_encoding('UTF-8').valid_encoding? @@ -127,6 +127,10 @@ module Banzai yield link, inner_html end + def unescape_link(href) + CGI.unescape(href) + end + def replace_text_when_pattern_matches(node, index, pattern) return unless node.text =~ pattern diff --git a/lib/banzai/filter/vulnerability_reference_filter.rb b/lib/banzai/filter/vulnerability_reference_filter.rb new file mode 100644 index 00000000000..a59e9836d69 --- /dev/null +++ b/lib/banzai/filter/vulnerability_reference_filter.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module Banzai + module Filter + # The actual filter is implemented in the EE mixin + class VulnerabilityReferenceFilter < IssuableReferenceFilter + self.reference_type = :vulnerability + + def self.object_class + Vulnerability + end + + private + + def project + context[:project] + end + end + end +end + +Banzai::Filter::VulnerabilityReferenceFilter.prepend_if_ee('EE::Banzai::Filter::VulnerabilityReferenceFilter') |