@@ -9,16 +9,20 @@ import {sanitize, defaultSchema} from './index.js'
9
9
10
10
test ( 'sanitize()' , function ( t ) {
11
11
t . test ( 'non-node' , function ( t ) {
12
+ // @ts -ignore runtime.
12
13
t . equal ( html ( sanitize ( true ) ) , '' , 'should ignore non-nodes (#1)' )
13
14
t . equal ( html ( sanitize ( null ) ) , '' , 'should ignore non-nodes (#2)' )
15
+ // @ts -ignore runtime.
14
16
t . equal ( html ( sanitize ( 1 ) ) , '' , 'should ignore non-nodes (#3)' )
17
+ // @ts -ignore runtime.
15
18
t . equal ( html ( sanitize ( [ ] ) ) , '' , 'should ignore non-nodes (#4)' )
16
19
17
20
t . end ( )
18
21
} )
19
22
20
23
t . test ( 'unknown nodes' , function ( t ) {
21
24
t . equal (
25
+ // @ts -ignore runtime.
22
26
html ( sanitize ( u ( 'unknown' , '<xml></xml>' ) ) ) ,
23
27
'' ,
24
28
'should ignore unknown nodes'
@@ -28,21 +32,25 @@ test('sanitize()', function (t) {
28
32
} )
29
33
30
34
t . test ( 'ignored nodes' , function ( t ) {
35
+ // @ts -ignore runtime.
31
36
t . equal ( html ( sanitize ( u ( 'raw' , '<xml></xml>' ) ) ) , '' , 'should ignore `raw`' )
32
37
33
38
t . equal (
39
+ // @ts -ignore runtime.
34
40
html ( sanitize ( u ( 'directive' , { name : '!alpha' } , '!alpha bravo' ) ) ) ,
35
41
'' ,
36
42
'should ignore declaration `directive`s'
37
43
)
38
44
39
45
t . equal (
46
+ // @ts -ignore runtime.
40
47
html ( sanitize ( u ( 'directive' , { name : '?xml' } , '?xml version="1.0"' ) ) ) ,
41
48
'' ,
42
49
'should ignore processing instruction `directive`s'
43
50
)
44
51
45
52
t . equal (
53
+ // @ts -ignore runtime.
46
54
html ( sanitize ( u ( 'characterData' , 'alpha' ) ) ) ,
47
55
'' ,
48
56
'should ignore `characterData`s'
@@ -65,6 +73,7 @@ test('sanitize()', function (t) {
65
73
)
66
74
67
75
t . equal (
76
+ // @ts -ignore runtime.
68
77
html ( sanitize ( u ( 'comment' , { toString} ) , { allowComments : true } ) ) ,
69
78
'<!---->' ,
70
79
'should ignore non-string `value`s with `allowComments: true`'
@@ -135,6 +144,7 @@ test('sanitize()', function (t) {
135
144
)
136
145
137
146
t . equal (
147
+ // @ts -ignore runtime.
138
148
html ( sanitize ( u ( 'text' , { toString} ) ) ) ,
139
149
'' ,
140
150
'should ignore non-string `value`s'
@@ -191,6 +201,7 @@ test('sanitize()', function (t) {
191
201
)
192
202
193
203
t . deepEqual (
204
+ // @ts -ignore runtime.
194
205
sanitize ( {
195
206
type : 'element' ,
196
207
properties : { } ,
@@ -201,6 +212,7 @@ test('sanitize()', function (t) {
201
212
)
202
213
203
214
t . deepEqual (
215
+ // @ts -ignore runtime.
204
216
sanitize ( { type : 'element' , tagName : 'div' } ) ,
205
217
h ( '' ) ,
206
218
'should support elements without children / properties'
@@ -294,12 +306,14 @@ test('sanitize()', function (t) {
294
306
)
295
307
296
308
t . deepEqual (
309
+ // @ts -ignore runtime.
297
310
sanitize ( u ( 'element' , { tagName : 'img' , properties : { alt : null } } ) ) ,
298
311
h ( 'img' ) ,
299
312
'should ignore `null`'
300
313
)
301
314
302
315
t . deepEqual (
316
+ // @ts -ignore runtime.
303
317
sanitize ( u ( 'element' , { tagName : 'img' , properties : { alt : undefined } } ) ) ,
304
318
h ( 'img' ) ,
305
319
'should ignore `undefined`'
@@ -318,18 +332,21 @@ test('sanitize()', function (t) {
318
332
)
319
333
320
334
t . deepEqual (
335
+ // @ts -ignore runtime.
321
336
sanitize ( u ( 'element' , { tagName : 'img' , properties : { alt : { toString} } } ) ) ,
322
337
h ( 'img' ) ,
323
338
'should ignore objects'
324
339
)
325
340
326
341
t . deepEqual (
327
342
sanitize (
343
+ // @ts -ignore runtime.
328
344
u ( 'element' , {
329
345
tagName : 'img' ,
330
346
properties : { alt : [ 1 , true , 'three' , [ 4 ] , { toString} ] }
331
347
} )
332
348
) ,
349
+ // @ts -ignore runtime.
333
350
h ( 'img' , { alt : [ 1 , true , 'three' ] } ) ,
334
351
'should supports arrays'
335
352
)
@@ -341,7 +358,7 @@ test('sanitize()', function (t) {
341
358
)
342
359
343
360
t . test ( 'href`' , function ( t ) {
344
- testAllURLs ( t , 'a' , 'href' , {
361
+ testAllUrls ( t , 'a' , 'href' , {
345
362
valid : {
346
363
anchor : '#heading' ,
347
364
relative : '/file.html' ,
@@ -367,7 +384,7 @@ test('sanitize()', function (t) {
367
384
} )
368
385
369
386
t . test ( '`cite`' , function ( t ) {
370
- testAllURLs ( t , 'blockquote' , 'cite' , {
387
+ testAllUrls ( t , 'blockquote' , 'cite' , {
371
388
valid : {
372
389
anchor : '#heading' ,
373
390
relative : '/file.html' ,
@@ -392,7 +409,7 @@ test('sanitize()', function (t) {
392
409
} )
393
410
394
411
t . test ( '`src`' , function ( t ) {
395
- testAllURLs ( t , 'img' , 'src' , {
412
+ testAllUrls ( t , 'img' , 'src' , {
396
413
valid : {
397
414
anchor : '#heading' ,
398
415
relative : '/file.html' ,
@@ -417,7 +434,7 @@ test('sanitize()', function (t) {
417
434
} )
418
435
419
436
t . test ( '`longDesc`' , function ( t ) {
420
- testAllURLs ( t , 'img' , 'longDesc' , {
437
+ testAllUrls ( t , 'img' , 'longDesc' , {
421
438
valid : {
422
439
anchor : '#heading' ,
423
440
relative : '/file.html' ,
@@ -664,18 +681,31 @@ function toString() {
664
681
return 'alert(1);'
665
682
}
666
683
667
- // Test `valid` and `invalid` `url`s in `prop` on `tagName`.
668
- function testAllURLs ( t , tagName , prop , all ) {
669
- testURLs ( t , tagName , prop , all . valid , true )
670
- testURLs ( t , tagName , prop , all . invalid , false )
684
+ /**
685
+ * Test `valid` and `invalid` `url`s in `prop` on `tagName`.
686
+ *
687
+ * @param {import('tape').Test } t
688
+ * @param {string } tagName
689
+ * @param {string } prop
690
+ * @param {{valid: Object.<string, string>, invalid: Object.<string, string>} } all
691
+ */
692
+ function testAllUrls ( t , tagName , prop , all ) {
693
+ testUrls ( t , tagName , prop , all . valid , true )
694
+ testUrls ( t , tagName , prop , all . invalid , false )
671
695
}
672
696
673
- // Test `valid` `url`s in `prop` on `tagName`.
674
- function testURLs ( t , tagName , prop , urls , valid ) {
697
+ /**
698
+ * Test `valid` `url`s in `prop` on `tagName`.
699
+ *
700
+ * @param {import('tape').Test } t
701
+ * @param {string } tagName
702
+ * @param {string } prop
703
+ * @param {Object.<string, string> } urls
704
+ * @param {boolean } valid
705
+ */
706
+ function testUrls ( t , tagName , prop , urls , valid ) {
675
707
Object . keys ( urls ) . forEach ( function ( name ) {
676
- var props = { }
677
-
678
- props [ prop ] = urls [ name ]
708
+ var props = { [ prop ] : urls [ name ] }
679
709
680
710
t . deepEqual (
681
711
sanitize ( h ( tagName , props ) ) ,
0 commit comments