Correctly sanitize MathML out of post content (#27107)
This commit is contained in:
parent
48f3ed738f
commit
7f4858b339
2 changed files with 59 additions and 0 deletions
|
@ -57,5 +57,25 @@ RSpec.describe Sanitize::Config do
|
|||
it 'keeps a with supported scheme and no host' do
|
||||
expect(Sanitize.fragment('<a href="dweb:/a/foo">Test</a>', subject)).to eq '<a href="dweb:/a/foo" rel="nofollow noopener noreferrer" target="_blank">Test</a>'
|
||||
end
|
||||
|
||||
it 'sanitizes math to LaTeX' do
|
||||
mathml = '<math><semantics><mrow><msup><mi>x</mi><mi>n</mi></msup><mo>+</mo><mi>y</mi></mrow><annotation encoding="application/x-tex">x^n+y</annotation></semantics></math>'
|
||||
expect(Sanitize.fragment(mathml, subject)).to eq '$x^n+y$'
|
||||
end
|
||||
|
||||
it 'sanitizes math blocks to LaTeX' do
|
||||
mathml = '<math display="block"><semantics><mrow><msup><mi>x</mi><mi>n</mi></msup><mo>+</mo><mi>y</mi></mrow><annotation encoding="application/x-tex">x^n+y</annotation></semantics></math>'
|
||||
expect(Sanitize.fragment(mathml, subject)).to eq '$$x^n+y$$'
|
||||
end
|
||||
|
||||
it 'math sanitizer falls back to plaintext' do
|
||||
mathml = '<math><semantics><msqrt><mi>x</mi></msqrt><annotation encoding="text/plain">sqrt(x)</annotation></semantics></math>'
|
||||
expect(Sanitize.fragment(mathml, subject)).to eq 'sqrt(x)'
|
||||
end
|
||||
|
||||
it 'prefers latex' do
|
||||
mathml = '<math><semantics><msqrt><mi>x</mi></msqrt><annotation encoding="text/plain">sqrt(x)</annotation><annotation encoding="application/x-tex">\\sqrt x</annotation></semantics></math>'
|
||||
expect(Sanitize.fragment(mathml, subject)).to eq '$\sqrt x$'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue