diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-20 14:18:08 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-20 14:18:08 +0300 |
commit | 5afcbe03ead9ada87621888a31a62652b10a7e4f (patch) | |
tree | 9918b67a0d0f0bafa6542e839a8be37adf73102d /lib/banzai | |
parent | c97c0201564848c1f53226fe19d71fdcc472f7d0 (diff) |
Add latest changes from gitlab-org/gitlab@16-4-stable-eev16.4.0-rc42
Diffstat (limited to 'lib/banzai')
19 files changed, 47 insertions, 42 deletions
diff --git a/lib/banzai/filter/ascii_doc_sanitization_filter.rb b/lib/banzai/filter/ascii_doc_sanitization_filter.rb index 67f5baf4635..4158aa8a5ec 100644 --- a/lib/banzai/filter/ascii_doc_sanitization_filter.rb +++ b/lib/banzai/filter/ascii_doc_sanitization_filter.rb @@ -8,7 +8,7 @@ module Banzai class AsciiDocSanitizationFilter < Banzai::Filter::BaseSanitizationFilter # Anchor link prefixed by "user-content-" pattern PREFIXED_ID_PATTERN = /\A#{Gitlab::Asciidoc::DEFAULT_ADOC_ATTRS['idprefix']}(:?[[:alnum:]]|-|_)+\z/.freeze - SECTION_HEADINGS = %w(h2 h3 h4 h5 h6).freeze + SECTION_HEADINGS = %w[h2 h3 h4 h5 h6].freeze # Footnote link patterns FOOTNOTE_LINK_ID_PATTERNS = { @@ -17,18 +17,18 @@ module Banzai }.freeze # Classes used by Asciidoctor to style components - ADMONITION_CLASSES = %w(fa icon-note icon-tip icon-warning icon-caution icon-important).freeze - ALIGNMENT_BUILTINS_CLASSES = %w(text-center text-left text-right text-justify).freeze + ADMONITION_CLASSES = %w[fa icon-note icon-tip icon-warning icon-caution icon-important].freeze + ALIGNMENT_BUILTINS_CLASSES = %w[text-center text-left text-right text-justify].freeze CALLOUT_CLASSES = ['conum'].freeze - CHECKLIST_CLASSES = %w(fa fa-check-square-o fa-square-o).freeze - LIST_CLASSES = %w(checklist none no-bullet unnumbered unstyled).freeze + CHECKLIST_CLASSES = %w[fa fa-check-square-o fa-square-o].freeze + LIST_CLASSES = %w[checklist none no-bullet unnumbered unstyled].freeze - TABLE_FRAME_CLASSES = %w(frame-all frame-topbot frame-sides frame-ends frame-none).freeze - TABLE_GRID_CLASSES = %w(grid-all grid-rows grid-cols grid-none).freeze - TABLE_STRIPES_CLASSES = %w(stripes-all stripes-odd stripes-even stripes-hover stripes-none).freeze + TABLE_FRAME_CLASSES = %w[frame-all frame-topbot frame-sides frame-ends frame-none].freeze + TABLE_GRID_CLASSES = %w[grid-all grid-rows grid-cols grid-none].freeze + TABLE_STRIPES_CLASSES = %w[stripes-all stripes-odd stripes-even stripes-hover stripes-none].freeze ELEMENT_CLASSES_ALLOWLIST = { - span: %w(big small underline overline line-through).freeze, + span: %w[big small underline overline line-through].freeze, div: ALIGNMENT_BUILTINS_CLASSES + ['admonitionblock'].freeze, td: ['icon'].freeze, i: ADMONITION_CLASSES + CALLOUT_CLASSES + CHECKLIST_CLASSES, @@ -44,14 +44,14 @@ module Banzai # Allow any classes in `span`, `i`, `div`, `td`, `ul`, `ol` and `a` elements # but then remove any unknown classes - allowlist[:attributes]['span'] = %w(class) + allowlist[:attributes]['span'] = %w[class] allowlist[:attributes]['div'].push('class') - allowlist[:attributes]['td'] = %w(class) - allowlist[:attributes]['i'] = %w(class) - allowlist[:attributes]['ul'] = %w(class) - allowlist[:attributes]['ol'] = %w(class) + allowlist[:attributes]['td'] = %w[class] + allowlist[:attributes]['i'] = %w[class] + allowlist[:attributes]['ul'] = %w[class] + allowlist[:attributes]['ol'] = %w[class] allowlist[:attributes]['a'].push('class') - allowlist[:attributes]['table'] = %w(class) + allowlist[:attributes]['table'] = %w[class] allowlist[:transformers].push(self.class.remove_element_classes) # Allow `id` in anchor and footnote elements @@ -60,7 +60,7 @@ module Banzai # Allow `id` in heading elements for section anchors SECTION_HEADINGS.each do |header| - allowlist[:attributes][header] = %w(id) + allowlist[:attributes][header] = %w[id] end # Remove ids that are not explicitly allowed diff --git a/lib/banzai/filter/autolink_filter.rb b/lib/banzai/filter/autolink_filter.rb index bbddaa37380..e877e5f316c 100644 --- a/lib/banzai/filter/autolink_filter.rb +++ b/lib/banzai/filter/autolink_filter.rb @@ -42,7 +42,7 @@ module Banzai ENTITY_UNTRUSTED_REGEX = Gitlab::UntrustedRegexp.new(ENTITY_UNTRUSTED, multiline: false) # Text matching LINK_PATTERN inside these elements will not be linked - IGNORE_PARENTS = %w(a code kbd pre script style).to_set + IGNORE_PARENTS = %w[a code kbd pre script style].to_set # The XPath query to use for finding text nodes to parse. TEXT_QUERY = %(descendant-or-self::text()[ diff --git a/lib/banzai/filter/base_sanitization_filter.rb b/lib/banzai/filter/base_sanitization_filter.rb index 0735fbb8d4c..938e1486195 100644 --- a/lib/banzai/filter/base_sanitization_filter.rb +++ b/lib/banzai/filter/base_sanitization_filter.rb @@ -14,7 +14,7 @@ module Banzai include Gitlab::Utils::StrongMemoize extend Gitlab::Utils::SanitizeNodeLink - UNSAFE_PROTOCOLS = %w(data javascript vbscript).freeze + UNSAFE_PROTOCOLS = %w[data javascript vbscript].freeze def allowlist strong_memoize(:allowlist) do @@ -24,9 +24,9 @@ module Banzai allowlist[:elements].push('span') # Allow data-math-style attribute in order to support LaTeX formatting - allowlist[:attributes]['code'] = %w(data-math-style) - allowlist[:attributes]['pre'] = %w(data-canonical-lang data-lang-params - data-math-style data-mermaid-style data-kroki-style) + allowlist[:attributes]['code'] = %w[data-math-style] + allowlist[:attributes]['pre'] = %w[data-canonical-lang data-lang-params + data-math-style data-mermaid-style data-kroki-style] # Allow html5 details/summary elements allowlist[:elements].push('details') @@ -34,7 +34,7 @@ module Banzai # Allow abbr elements with title attribute allowlist[:elements].push('abbr') - allowlist[:attributes]['abbr'] = %w(title) + allowlist[:attributes]['abbr'] = %w[title] # Disallow `name` attribute globally, allow on `a` allowlist[:attributes][:all].delete('name') diff --git a/lib/banzai/filter/broadcast_message_sanitization_filter.rb b/lib/banzai/filter/broadcast_message_sanitization_filter.rb index 183908d02a9..e55e1901b4f 100644 --- a/lib/banzai/filter/broadcast_message_sanitization_filter.rb +++ b/lib/banzai/filter/broadcast_message_sanitization_filter.rb @@ -11,7 +11,7 @@ module Banzai allowlist[:attributes]['a'].push('class', 'style') - allowlist[:css] = { properties: %w(color border background padding margin text-decoration) } + allowlist[:css] = { properties: %w[color border background padding margin text-decoration] } allowlist end diff --git a/lib/banzai/filter/code_language_filter.rb b/lib/banzai/filter/code_language_filter.rb index 60e5a4063df..a5ae3817d83 100644 --- a/lib/banzai/filter/code_language_filter.rb +++ b/lib/banzai/filter/code_language_filter.rb @@ -32,12 +32,17 @@ module Banzai lang, lang_params = parse_lang_params(code_node) pre_node = code_node.parent - pre_node.remove_attribute('lang') if lang.present? + if lang.present? + code_node.remove_attribute('lang') + pre_node.remove_attribute('lang') + end + pre_node.set_attribute(LANG_ATTR, escape_once(lang)) if lang.present? pre_node.set_attribute(LANG_PARAMS_ATTR, escape_once(lang_params)) if lang_params.present? # cmark-gfm added this, it's now in data-lang-params pre_node.remove_attribute('data-meta') + code_node.remove_attribute('data-meta') end private @@ -55,14 +60,14 @@ module Banzai # "```suggestion:+1-10 more```" -> '<pre data-canonical-lang="suggestion" data-lang-params="+1-10 more">'. def parse_lang_params(code_node) pre_node = code_node.parent - language = pre_node.attr('lang') + language = pre_node.attr('lang') || code_node.attr('lang') return unless language language, language_params = language.split(LANG_PARAMS_DELIMITER, 2) # cmark-gfm places extra lang parameters into data-meta - language_params = [pre_node.attr('data-meta'), language_params].compact.join(' ') + language_params = [pre_node.attr('data-meta'), code_node.attr('data-meta'), language_params].compact.join(' ') [language, language_params] end diff --git a/lib/banzai/filter/custom_emoji_filter.rb b/lib/banzai/filter/custom_emoji_filter.rb index b589d264526..dddaaebc9de 100644 --- a/lib/banzai/filter/custom_emoji_filter.rb +++ b/lib/banzai/filter/custom_emoji_filter.rb @@ -5,7 +5,7 @@ module Banzai class CustomEmojiFilter < HTML::Pipeline::Filter include Gitlab::Utils::StrongMemoize - IGNORED_ANCESTOR_TAGS = %w(pre code tt).to_set + IGNORED_ANCESTOR_TAGS = %w[pre code tt].to_set def call return doc unless resource_parent diff --git a/lib/banzai/filter/emoji_filter.rb b/lib/banzai/filter/emoji_filter.rb index d8c9fd0a7f0..33c93b169f4 100644 --- a/lib/banzai/filter/emoji_filter.rb +++ b/lib/banzai/filter/emoji_filter.rb @@ -7,7 +7,7 @@ module Banzai # # Based on HTML::Pipeline::EmojiFilter class EmojiFilter < HTML::Pipeline::Filter - IGNORED_ANCESTOR_TAGS = %w(pre code tt).to_set + IGNORED_ANCESTOR_TAGS = %w[pre code tt].to_set def call doc.xpath('descendant-or-self::text()').each do |node| diff --git a/lib/banzai/filter/gollum_tags_filter.rb b/lib/banzai/filter/gollum_tags_filter.rb index 0548d5a9997..ade4f82e54b 100644 --- a/lib/banzai/filter/gollum_tags_filter.rb +++ b/lib/banzai/filter/gollum_tags_filter.rb @@ -57,7 +57,7 @@ module Banzai ALLOWED_IMAGE_EXTENSIONS = /.+(jpg|png|gif|svg|bmp)\z/i.freeze # Do not perform linking inside these tags. - IGNORED_ANCESTOR_TAGS = %w(pre code tt).to_set + IGNORED_ANCESTOR_TAGS = %w[pre code tt].to_set def call doc.xpath('descendant-or-self::text()').each do |node| @@ -115,7 +115,7 @@ module Banzai end def url?(path) - path.start_with?(*%w(http https)) + path.start_with?(*%w[http https]) end # Attempt to process the tag as a page link tag. diff --git a/lib/banzai/filter/inline_diff_filter.rb b/lib/banzai/filter/inline_diff_filter.rb index fc77984f135..b886c68716b 100644 --- a/lib/banzai/filter/inline_diff_filter.rb +++ b/lib/banzai/filter/inline_diff_filter.rb @@ -4,7 +4,7 @@ module Banzai module Filter class InlineDiffFilter < HTML::Pipeline::Filter - IGNORED_ANCESTOR_TAGS = %w(pre code tt).to_set + IGNORED_ANCESTOR_TAGS = %w[pre code tt].to_set INLINE_DIFF_DELETION_UNTRUSTED = '(?:\[\-(.*?)\-\]|\{\-(.*?)\-\})' INLINE_DIFF_DELETION_UNTRUSTED_REGEX = diff --git a/lib/banzai/filter/issuable_reference_expansion_filter.rb b/lib/banzai/filter/issuable_reference_expansion_filter.rb index 1c3e25b3b27..22fbaa11066 100644 --- a/lib/banzai/filter/issuable_reference_expansion_filter.rb +++ b/lib/banzai/filter/issuable_reference_expansion_filter.rb @@ -11,7 +11,7 @@ module Banzai include Gitlab::Utils::StrongMemoize NUMBER_OF_SUMMARY_ASSIGNEES = 2 - VISIBLE_STATES = %w(closed merged).freeze + VISIBLE_STATES = %w[closed merged].freeze EXTENDED_FORMAT_XPATH = Gitlab::Utils::Nokogiri.css_to_xpath('a[data-reference-format="+s"]') def call diff --git a/lib/banzai/filter/references/reference_filter.rb b/lib/banzai/filter/references/reference_filter.rb index 5353d3f4e49..caec808ef04 100644 --- a/lib/banzai/filter/references/reference_filter.rb +++ b/lib/banzai/filter/references/reference_filter.rb @@ -151,7 +151,7 @@ module Banzai def ignore_ancestor_query @ignore_ancestor_query ||= begin - parents = %w(pre code a style) + parents = %w[pre code a style] parents << 'blockquote' if context[:ignore_blockquotes] parents.map { |n| "ancestor::#{n}" }.join(' or ') diff --git a/lib/banzai/filter/repository_link_filter.rb b/lib/banzai/filter/repository_link_filter.rb index e06126bdf0f..028a081075d 100644 --- a/lib/banzai/filter/repository_link_filter.rb +++ b/lib/banzai/filter/repository_link_filter.rb @@ -114,7 +114,7 @@ module Banzai # Repository routes are under /-/ scope now. # Since we craft a path without using route helpers we must # ensure - is added here. - prefix = '-' if %w(tree blob raw commits).include?(resource_type.to_s) + prefix = '-' if %w[tree blob raw commits].include?(resource_type.to_s) uri.path = [ relative_url_root, diff --git a/lib/banzai/filter/sanitization_filter.rb b/lib/banzai/filter/sanitization_filter.rb index c2cad237d6f..15013c8595e 100644 --- a/lib/banzai/filter/sanitization_filter.rb +++ b/lib/banzai/filter/sanitization_filter.rb @@ -33,7 +33,7 @@ module Banzai # Allow section elements with data-footnotes attribute allowlist[:elements].push('section') - allowlist[:attributes]['section'] = %w(data-footnotes) + allowlist[:attributes]['section'] = %w[data-footnotes] allowlist[:attributes]['a'].push('data-footnote-ref', 'data-footnote-backref', 'data-footnote-backref-idx') allowlist diff --git a/lib/banzai/filter/spaced_link_filter.rb b/lib/banzai/filter/spaced_link_filter.rb index d370a585271..9331e72cd36 100644 --- a/lib/banzai/filter/spaced_link_filter.rb +++ b/lib/banzai/filter/spaced_link_filter.rb @@ -39,7 +39,7 @@ module Banzai ) # Text matching LINK_OR_IMAGE_PATTERN inside these elements will not be linked - IGNORE_PARENTS = %w(a code kbd pre script style).to_set + IGNORE_PARENTS = %w[a code kbd pre script style].to_set # The XPath query to use for finding text nodes to parse. TEXT_QUERY = %(descendant-or-self::text()[ diff --git a/lib/banzai/filter/syntax_highlight_filter.rb b/lib/banzai/filter/syntax_highlight_filter.rb index e02d668a1ca..6888e0d19e5 100644 --- a/lib/banzai/filter/syntax_highlight_filter.rb +++ b/lib/banzai/filter/syntax_highlight_filter.rb @@ -93,7 +93,7 @@ module Banzai end def use_rouge?(language) - (%w(math suggestion) + ::AsciidoctorExtensions::Kroki::SUPPORTED_DIAGRAM_NAMES).exclude?(language) + (%w[math suggestion] + ::AsciidoctorExtensions::Kroki::SUPPORTED_DIAGRAM_NAMES).exclude?(language) end end end diff --git a/lib/banzai/filter/table_of_contents_filter.rb b/lib/banzai/filter/table_of_contents_filter.rb index de3e978b320..abd1003fde0 100644 --- a/lib/banzai/filter/table_of_contents_filter.rb +++ b/lib/banzai/filter/table_of_contents_filter.rb @@ -55,7 +55,7 @@ module Banzai def anchor_tag(href) escaped_href = CGI.escape(href) # account for non-ASCII characters - %{<a id="user-content-#{href}" class="anchor" href="##{escaped_href}" aria-hidden="true"></a>} + %(<a id="user-content-#{href}" class="anchor" href="##{escaped_href}" aria-hidden="true"></a>) end def push_toc(children, root: false) @@ -69,7 +69,7 @@ module Banzai end def push_anchor(header_node) - result[:toc] << %{<li><a href="##{header_node.href}">#{header_node.text}</a>} + result[:toc] << %(<li><a href="##{header_node.href}">#{header_node.text}</a>) push_toc(header_node.children) result[:toc] << '</li>' end diff --git a/lib/banzai/pipeline/base_pipeline.rb b/lib/banzai/pipeline/base_pipeline.rb index 87d1cf9912f..249b332be78 100644 --- a/lib/banzai/pipeline/base_pipeline.rb +++ b/lib/banzai/pipeline/base_pipeline.rb @@ -16,7 +16,7 @@ module Banzai end class << self - %i(call to_document to_html).each do |meth| + %i[call to_document to_html].each do |meth| define_method(meth) do |text, context| context = transform_context(context) diff --git a/lib/banzai/pipeline/description_pipeline.rb b/lib/banzai/pipeline/description_pipeline.rb index 8f8ce1cbd41..8236c7092d2 100644 --- a/lib/banzai/pipeline/description_pipeline.rb +++ b/lib/banzai/pipeline/description_pipeline.rb @@ -4,7 +4,7 @@ module Banzai module Pipeline class DescriptionPipeline < FullPipeline ALLOWLIST = Banzai::Filter::SanitizationFilter::LIMITED.deep_dup.merge( - elements: Banzai::Filter::SanitizationFilter::LIMITED[:elements] - %w(pre code img ol ul li) + elements: Banzai::Filter::SanitizationFilter::LIMITED[:elements] - %w[pre code img ol ul li] ) def self.transform_context(context) diff --git a/lib/banzai/pipeline/incident_management/timeline_event_pipeline.rb b/lib/banzai/pipeline/incident_management/timeline_event_pipeline.rb index eef2b2674dd..b00b4dd85b5 100644 --- a/lib/banzai/pipeline/incident_management/timeline_event_pipeline.rb +++ b/lib/banzai/pipeline/incident_management/timeline_event_pipeline.rb @@ -5,7 +5,7 @@ module Banzai module IncidentManagement class TimelineEventPipeline < PlainMarkdownPipeline ALLOWLIST = Banzai::Filter::SanitizationFilter::LIMITED.deep_dup.merge( - elements: %w(p b i strong em pre code a img) + elements: %w[p b i strong em pre code a img] ).freeze def self.filters |