Merge commit from fork

* add guard clause to check for node attributes

* check for encoding attribute specifically

* check for encoding attribute specifically

* change spec
This commit is contained in:
Pia B. 2026-06-03 12:12:37 +02:00 committed by GitHub
parent c2daca655f
commit 07236016bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View File

@ -83,8 +83,10 @@ class Sanitize
# next, we find the plain-text description
is_annotation_with_encoding = lambda do |encoding, node|
return false unless node.name == 'annotation'
encoding_attr = node.attributes['encoding']
return false if encoding_attr.nil?
node.attributes['encoding'].value == encoding
encoding_attr.value == encoding
end
annotation = semantics.children.find(&is_annotation_with_encoding.curry['application/x-tex'])

View File

@ -38,6 +38,14 @@ RSpec.describe Sanitize::Config do
expect(Sanitize.fragment('<a href="foo://bar">Test&lt;a href="https://example.com"&gt;test&lt;/a&gt;</a>', subject)).to eq 'Test&lt;a href="https://example.com"&gt;test&lt;/a&gt;'
end
it 'removes math when unparsable due to missing attributes' do
expect(Sanitize.fragment('<math><semantics><annotation>x</annotation></semantics></math>', subject)).to eq ''
end
it 'removes math when unparsable due to missing encoding attribute' do
expect(Sanitize.fragment('<math><semantics><annotation class="foo">x</annotation></semantics></math>', subject)).to eq ''
end
it 'keeps a with href' do
expect(Sanitize.fragment('<a href="http://example.com">Test</a>', subject)).to eq '<a href="http://example.com" rel="nofollow noopener" target="_blank">Test</a>'
end