@@ -5,59 +5,61 @@ import { serialize, toScript, fromScript } from '..';
5
5
6
6
describe ( 'escaping' , ( ) => {
7
7
it ( 'escapes' , ( ) => {
8
- const html = serialize ( 'foo' , '' , { foo : '</script>' , bar : '>' } ) ;
8
+ const html = serialize ( 'foo' , '' , { foo : '</script>' , bar : '>' , baz : '</script ' } ) ;
9
9
10
10
assert . include ( html , '</script>' ) ;
11
11
assert . include ( html , '&gt;' ) ;
12
+ assert . include ( html , '</script ' ) ;
12
13
} ) ;
13
14
14
15
wrap ( )
15
- . withGlobal ( 'document' , ( ) => ( { } ) )
16
- . describe ( 'with fromScript' , ( ) => {
17
- it ( 'loads the escaped content correctly' , ( ) => {
18
- const html = toScript ( { a : 'b' } , { foo : '</script>' , bar : '>' , baz : '&' } ) ;
19
- const $ = cheerio . load ( html ) ;
16
+ . withGlobal ( 'document' , ( ) => ( { } ) )
17
+ . describe ( 'with fromScript' , ( ) => {
18
+ it ( 'loads the escaped content correctly' , ( ) => {
19
+ const html = toScript ( { a : 'b' } , { foo : '</script>' , bar : '>' , baz : '&' , foobar : '</script x ' } ) ;
20
+ const $ = cheerio . load ( html ) ;
20
21
21
- global . document . querySelector = ( ) => ( { innerHTML : $ ( $ ( 'script' ) [ 0 ] ) . html ( ) } ) ;
22
+ global . document . querySelector = ( ) => ( { innerHTML : $ ( $ ( 'script' ) [ 0 ] ) . html ( ) } ) ;
22
23
23
- const res = fromScript ( {
24
- a : 'b' ,
25
- } ) ;
26
-
27
- assert . isObject ( res ) ;
24
+ const res = fromScript ( {
25
+ a : 'b' ,
26
+ } ) ;
28
27
29
- assert . equal ( res . foo , '</script>' ) ;
30
- assert . equal ( res . bar , '>' ) ;
31
- assert . equal ( res . baz , '&' ) ;
32
- } ) ;
28
+ assert . isObject ( res ) ;
33
29
34
- it ( 'escapes multiple times the same, with interleaved decoding' , ( ) => {
35
- const makeHTML = ( ) => toScript ( { attr : 'key' } , {
36
- props : 'yay' ,
37
- needsEncoding : '" > </script>' , // "needsEncoding" is necessary
30
+ assert . equal ( res . foo , '</script>' ) ;
31
+ assert . equal ( res . bar , '>' ) ;
32
+ assert . equal ( res . baz , '&' ) ;
33
+ assert . equal ( res . foobar , ' </script x' ) ;
38
34
} ) ;
39
- const script1 = makeHTML ( ) ;
40
- const script2 = makeHTML ( ) ;
41
- assert . equal ( script1 , script2 , 'two successive toScripts result in identical HTML' ) ;
42
35
43
- const $ = cheerio . load ( script1 ) ;
36
+ it ( 'escapes multiple times the same, with interleaved decoding' , ( ) => {
37
+ const makeHTML = ( ) => toScript ( { attr : 'key' } , {
38
+ props : 'yay' ,
39
+ needsEncoding : '" > </script>' , // "needsEncoding" is necessary
40
+ } ) ;
41
+ const script1 = makeHTML ( ) ;
42
+ const script2 = makeHTML ( ) ;
43
+ assert . equal ( script1 , script2 , 'two successive toScripts result in identical HTML' ) ;
44
44
45
- global . document . querySelector = ( ) => ( { innerHTML : $ ( $ ( 'script' ) [ 0 ] ) . html ( ) } ) ;
45
+ const $ = cheerio . load ( script1 ) ;
46
46
47
- const res = fromScript ( { attr : 'key' } ) ;
47
+ global . document . querySelector = ( ) => ( { innerHTML : $ ( $ ( 'script' ) [ 0 ] ) . html ( ) } ) ;
48
48
49
- const script3 = makeHTML ( ) ;
50
- assert . equal (
51
- script1 ,
52
- script3 ,
53
- 'third toScript after a fromScript call results in the same HTML' ,
54
- ) ;
49
+ const res = fromScript ( { attr : 'key' } ) ;
55
50
56
- assert . isObject ( res ) ;
51
+ const script3 = makeHTML ( ) ;
52
+ assert . equal (
53
+ script1 ,
54
+ script3 ,
55
+ 'third toScript after a fromScript call results in the same HTML' ,
56
+ ) ;
57
57
58
- assert . equal ( res . props , 'yay' ) ;
58
+ assert . isObject ( res ) ;
59
+
60
+ assert . equal ( res . props , 'yay' ) ;
61
+ } ) ;
59
62
} ) ;
60
- } ) ;
61
63
62
64
it ( 'escapes quotes and fixes data attributes' , ( ) => {
63
65
const markup = toScript ( {
0 commit comments