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:
parent
c2daca655f
commit
07236016bc
@ -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'])
|
||||
|
||||
@ -38,6 +38,14 @@ RSpec.describe Sanitize::Config do
|
||||
expect(Sanitize.fragment('<a href="foo://bar">Test<a href="https://example.com">test</a></a>', subject)).to eq 'Test<a href="https://example.com">test</a>'
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user