mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 07:53:49 +08:00
FIX: Handle null svg class for excerpt parsing (#19276)
Follow-up to 9d50790530459535164870bd49e712c30d2d5e8e In certain cases the svg may not a class, so we just need safe navigation to avoid an error here.
This commit is contained in:
@ -136,7 +136,7 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
|
|||||||
|
|
||||||
when "svg"
|
when "svg"
|
||||||
attributes = Hash[*attributes.flatten]
|
attributes = Hash[*attributes.flatten]
|
||||||
if attributes["class"].include?("d-icon") && @keep_svg
|
if attributes["class"]&.include?("d-icon") && @keep_svg
|
||||||
include_tag(name, attributes)
|
include_tag(name, attributes)
|
||||||
@in_svg = true
|
@in_svg = true
|
||||||
end
|
end
|
||||||
|
@ -42,6 +42,9 @@ RSpec.describe ExcerptParser do
|
|||||||
html = '<svg class="blah"><use href="#folder"></use></svg>'
|
html = '<svg class="blah"><use href="#folder"></use></svg>'
|
||||||
expect(ExcerptParser.get_excerpt(html, 100, { keep_svg: true })).to match_html('')
|
expect(ExcerptParser.get_excerpt(html, 100, { keep_svg: true })).to match_html('')
|
||||||
|
|
||||||
|
html = '<svg><use href="#folder"></use></svg>'
|
||||||
|
expect(ExcerptParser.get_excerpt(html, 100, { keep_svg: true })).to match_html('')
|
||||||
|
|
||||||
html = '<use href="#user"></use><svg class="fa d-icon d-icon-folder svg-icon svg-node"><use href="#folder"></use></svg>'
|
html = '<use href="#user"></use><svg class="fa d-icon d-icon-folder svg-icon svg-node"><use href="#folder"></use></svg>'
|
||||||
expect(ExcerptParser.get_excerpt(html, 100, { keep_svg: true })).to match_html('<svg class="fa d-icon d-icon-folder svg-icon svg-node"><use href="#folder"></use></svg>')
|
expect(ExcerptParser.get_excerpt(html, 100, { keep_svg: true })).to match_html('<svg class="fa d-icon d-icon-folder svg-icon svg-node"><use href="#folder"></use></svg>')
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user