1
1
import test from 'tape'
2
- import html from 'hast-util-to-html'
2
+ import { toHtml } from 'hast-util-to-html'
3
3
import { h , s } from 'hastscript'
4
4
import { u } from 'unist-builder'
5
5
import deepmerge from 'deepmerge'
@@ -12,21 +12,21 @@ const own = {}.hasOwnProperty
12
12
test ( 'sanitize()' , ( t ) => {
13
13
t . test ( 'non-node' , ( t ) => {
14
14
// @ts -expect-error runtime.
15
- t . equal ( html ( sanitize ( true ) ) , '' , 'should ignore non-nodes (#1)' )
15
+ t . equal ( toHtml ( sanitize ( true ) ) , '' , 'should ignore non-nodes (#1)' )
16
16
// @ts -expect-error runtime.
17
- t . equal ( html ( sanitize ( null ) ) , '' , 'should ignore non-nodes (#2)' )
17
+ t . equal ( toHtml ( sanitize ( null ) ) , '' , 'should ignore non-nodes (#2)' )
18
18
// @ts -expect-error runtime.
19
- t . equal ( html ( sanitize ( 1 ) ) , '' , 'should ignore non-nodes (#3)' )
19
+ t . equal ( toHtml ( sanitize ( 1 ) ) , '' , 'should ignore non-nodes (#3)' )
20
20
// @ts -expect-error runtime.
21
- t . equal ( html ( sanitize ( [ ] ) ) , '' , 'should ignore non-nodes (#4)' )
21
+ t . equal ( toHtml ( sanitize ( [ ] ) ) , '' , 'should ignore non-nodes (#4)' )
22
22
23
23
t . end ( )
24
24
} )
25
25
26
26
t . test ( 'unknown nodes' , ( t ) => {
27
27
t . equal (
28
28
// @ts -expect-error runtime.
29
- html ( sanitize ( u ( 'unknown' , '<xml></xml>' ) ) ) ,
29
+ toHtml ( sanitize ( u ( 'unknown' , '<xml></xml>' ) ) ) ,
30
30
'' ,
31
31
'should ignore unknown nodes'
32
32
)
@@ -35,26 +35,30 @@ test('sanitize()', (t) => {
35
35
} )
36
36
37
37
t . test ( 'ignored nodes' , ( t ) => {
38
- // @ts -expect-error runtime.
39
- t . equal ( html ( sanitize ( u ( 'raw' , '<xml></xml>' ) ) ) , '' , 'should ignore `raw`' )
38
+ t . equal (
39
+ // @ts -expect-error runtime.
40
+ toHtml ( sanitize ( u ( 'raw' , '<xml></xml>' ) ) ) ,
41
+ '' ,
42
+ 'should ignore `raw`'
43
+ )
40
44
41
45
t . equal (
42
46
// @ts -expect-error runtime.
43
- html ( sanitize ( u ( 'directive' , { name : '!alpha' } , '!alpha bravo' ) ) ) ,
47
+ toHtml ( sanitize ( u ( 'directive' , { name : '!alpha' } , '!alpha bravo' ) ) ) ,
44
48
'' ,
45
49
'should ignore declaration `directive`s'
46
50
)
47
51
48
52
t . equal (
49
53
// @ts -expect-error runtime.
50
- html ( sanitize ( u ( 'directive' , { name : '?xml' } , '?xml version="1.0"' ) ) ) ,
54
+ toHtml ( sanitize ( u ( 'directive' , { name : '?xml' } , '?xml version="1.0"' ) ) ) ,
51
55
'' ,
52
56
'should ignore processing instruction `directive`s'
53
57
)
54
58
55
59
t . equal (
56
60
// @ts -expect-error runtime.
57
- html ( sanitize ( u ( 'characterData' , 'alpha' ) ) ) ,
61
+ toHtml ( sanitize ( u ( 'characterData' , 'alpha' ) ) ) ,
58
62
'' ,
59
63
'should ignore `characterData`s'
60
64
)
@@ -64,26 +68,26 @@ test('sanitize()', (t) => {
64
68
65
69
t . test ( '`comment`' , ( t ) => {
66
70
t . equal (
67
- html ( sanitize ( u ( 'comment' , 'alpha' ) ) ) ,
71
+ toHtml ( sanitize ( u ( 'comment' , 'alpha' ) ) ) ,
68
72
'' ,
69
73
'should ignore `comment`s by default'
70
74
)
71
75
72
76
t . equal (
73
- html ( sanitize ( u ( 'comment' , 'alpha' ) , { allowComments : true } ) ) ,
77
+ toHtml ( sanitize ( u ( 'comment' , 'alpha' ) , { allowComments : true } ) ) ,
74
78
'<!--alpha-->' ,
75
79
'should allow `comment`s with `allowComments: true`'
76
80
)
77
81
78
82
t . equal (
79
83
// @ts -expect-error runtime.
80
- html ( sanitize ( u ( 'comment' , { toString} ) , { allowComments : true } ) ) ,
84
+ toHtml ( sanitize ( u ( 'comment' , { toString} ) , { allowComments : true } ) ) ,
81
85
'<!---->' ,
82
86
'should ignore non-string `value`s with `allowComments: true`'
83
87
)
84
88
85
89
t . equal (
86
- html (
90
+ toHtml (
87
91
sanitize ( u ( 'comment' , 'alpha--><script>alert(1)</script><!--bravo' ) , {
88
92
allowComments : true
89
93
} )
@@ -97,13 +101,13 @@ test('sanitize()', (t) => {
97
101
98
102
t . test ( '`doctype`' , ( t ) => {
99
103
t . equal (
100
- html ( sanitize ( u ( 'doctype' , { name : 'html' } , 'alpha' ) ) ) ,
104
+ toHtml ( sanitize ( u ( 'doctype' , { name : 'html' } , 'alpha' ) ) ) ,
101
105
'' ,
102
106
'should ignore `doctype`s by default'
103
107
)
104
108
105
109
t . equal (
106
- html (
110
+ toHtml (
107
111
sanitize ( u ( 'doctype' , { name : 'html' } , 'alpha' ) , { allowDoctypes : true } )
108
112
) ,
109
113
'<!doctype html>' ,
@@ -142,26 +146,26 @@ test('sanitize()', (t) => {
142
146
)
143
147
144
148
t . equal (
145
- html ( sanitize ( u ( 'text' , 'alert(1)' ) ) ) ,
149
+ toHtml ( sanitize ( u ( 'text' , 'alert(1)' ) ) ) ,
146
150
'alert(1)' ,
147
151
'should allow `text`'
148
152
)
149
153
150
154
t . equal (
151
155
// @ts -expect-error runtime.
152
- html ( sanitize ( u ( 'text' , { toString} ) ) ) ,
156
+ toHtml ( sanitize ( u ( 'text' , { toString} ) ) ) ,
153
157
'' ,
154
158
'should ignore non-string `value`s'
155
159
)
156
160
157
161
t . equal (
158
- html ( sanitize ( h ( 'script' , u ( 'text' , 'alert(1)' ) ) ) ) ,
162
+ toHtml ( sanitize ( h ( 'script' , u ( 'text' , 'alert(1)' ) ) ) ) ,
159
163
'' ,
160
164
'should ignore `text` in `script` elements'
161
165
)
162
166
163
167
t . equal (
164
- html ( sanitize ( h ( 'style' , u ( 'text' , 'alert(1)' ) ) ) ) ,
168
+ toHtml ( sanitize ( h ( 'style' , u ( 'text' , 'alert(1)' ) ) ) ) ,
165
169
'alert(1)' ,
166
170
'should show `text` in `style` elements'
167
171
)
0 commit comments