FIX: Allow svg in oneboxer in certain cases (#19253)

When doing local oneboxes we sometimes want to allow
SVGs in the final preview HTML. The main case currently
is for the new cooked hashtags, which include an SVG
icon.

SVGs will be included in local oneboxes via `ExcerptParser` _only_
if they have the d-icon class, and if the caller for `post.excerpt`
specifies the `keep_svg: true` option.
This commit is contained in:
Martin Brennan
2022-11-30 12:42:15 +10:00
committed by GitHub
parent e669cf3648
commit 9d50790530
4 changed files with 41 additions and 2 deletions

View File

@ -34,6 +34,18 @@ RSpec.describe ExcerptParser do
expect(ExcerptParser.get_excerpt(html, 2, {})).to match_html('<details class="disabled"><summary>fo&hellip;</summary></details>')
end
it "allows <svg> with <use> inside for icons when keep_svg is true" do
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>')
expect(ExcerptParser.get_excerpt(html, 100, {})).to match_html('')
html = '<svg class="blah"><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>'
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
describe "keep_onebox_body parameter" do
it "keeps the body content for external oneboxes" do
html = <<~HTML.strip