import PrettyText, { buildOptions } from "pretty-text/pretty-text"; import { module, test } from "qunit"; import { hrefAllowed } from "pretty-text/sanitizer"; module("Unit | Utility | sanitizer", function () { test("sanitize", function (assert) { const pt = new PrettyText( buildOptions({ siteSettings: { allowed_iframes: "https://www.google.com/maps/embed?|https://www.openstreetmap.org/export/embed.html?", }, }) ); const cooked = (input, expected, text) => assert.strictEqual(pt.cook(input), expected.replace(/\/>/g, ">"), text); assert.strictEqual( pt.sanitize('bug'), "bug" ); assert.strictEqual( pt.sanitize("
"), "
" ); assert.strictEqual( pt.sanitize("

hello

"), "

hello

" ); assert.strictEqual(pt.sanitize("<3 <3"), "<3 <3"); assert.strictEqual(pt.sanitize("<_<"), "<_<"); cooked( "hello", "

hello

", "it sanitizes while cooking" ); cooked( "disney reddit", '

disney reddit

', "we can embed proper links" ); cooked("
hello
", "hello", "it does not allow centering"); cooked( "
a\n
\n", "
a\n
", "it does not double sanitize" ); cooked( '', "", "it does not allow most iframes" ); cooked( '', '', "it allows iframe to google maps" ); cooked( '', '', "it allows iframe to OpenStreetMap" ); assert.strictEqual(pt.sanitize(""), "hullo"); assert.strictEqual(pt.sanitize(""), "press me!"); assert.strictEqual(pt.sanitize("draw me!"), "draw me!"); assert.strictEqual(pt.sanitize("hello"), "hello"); cooked( "[the answer](javascript:alert(42))", "

[the answer](javascript:alert(42))

", "it prevents XSS" ); cooked( '\n', "

", "it doesn't circumvent XSS with comments" ); cooked( 'a', "

a

", "it sanitizes spans" ); cooked( 'a', "

a

", "it sanitizes spans" ); cooked( 'a', '

a

', "it sanitizes spans" ); cooked( "Ctrl+C", "

Ctrl+C

" ); cooked( "it has been 1 day 0 days since our last test failure", "

it has been 1 day 0 days since our last test failure

" ); cooked( `it has been 1 day 0 days since our last test failure`, `

it has been 1 day 0 days since our last test failure

` ); cooked( `
hello
`, `
hello
` ); cooked( `1 + 1 is 3 2`, `

1 + 1 is 3 2

` ); cooked( `JS`, `

JS

` ); cooked( `
Forum
Software
`, `
Forum
Software
` ); cooked( `high low HUGE`, `

high low HUGE

` ); cooked(`
RTL text
`, `
RTL text
`); cooked( `
`, `
` ); }); test("ids on headings", function (assert) { const pt = new PrettyText(buildOptions({ siteSettings: {} })); assert.strictEqual( pt.sanitize("

Test Heading

"), "

Test Heading

" ); assert.strictEqual( pt.sanitize(`

Test Heading

`), `

Test Heading

` ); assert.strictEqual( pt.sanitize(`

Test Heading

`), `

Test Heading

` ); assert.strictEqual( pt.sanitize(`

Test Heading

`), `

Test Heading

` ); assert.strictEqual( pt.sanitize(`

Test Heading

`), `

Test Heading

` ); assert.strictEqual( pt.sanitize(`
Test Heading
`), `
Test Heading
` ); assert.strictEqual( pt.sanitize(`
Test Heading
`), `
Test Heading
` ); }); test("autoplay videos must be muted", function (assert) { let pt = new PrettyText(buildOptions({ siteSettings: {} })); assert.ok( pt .sanitize( `

Hey