-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.js
27 lines (23 loc) · 872 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import assert from 'node:assert/strict'
import test from 'node:test'
import merge from 'deepmerge'
import {rehype} from 'rehype'
import rehypeSanitize, {defaultSchema} from './index.js'
test('rehypeSanitize', async function (t) {
await t.test('should work', async function () {
const file = await rehype()
.use(rehypeSanitize)
.process('<img onmouseover="alert(\'alpha\')">')
assert.equal(file.messages.length, 0)
assert.equal(String(file), '<img>')
})
await t.test('should support options', async function () {
const file = await rehype()
.use(rehypeSanitize, merge(defaultSchema, {tagNames: ['math', 'mi']}))
.process(
'<math><mi xlink:href="data:x,<script>alert(\'echo\')</script>"></mi></math>'
)
assert.equal(file.messages.length, 0)
assert.equal(String(file), '<math><mi></mi></math>')
})
})