@@ -19,31 +19,22 @@ const escape_html_dict = {
19
19
'<' : '<'
20
20
} ;
21
21
22
+ const surrogates = // high surrogate without paired low surrogate
23
+ '[\\ud800-\\udbff](?![\\udc00-\\udfff])|' +
24
+ // a valid surrogate pair, the only match with 2 code units
25
+ // we match it so that we can match unpaired low surrogates in the same pass
26
+ // TODO: use lookbehind assertions once they are widely supported: (?<![\ud800-udbff])[\udc00-\udfff]
27
+ '[\\ud800-\\udbff][\\udc00-\\udfff]|' +
28
+ // unpaired low surrogate (see previous match)
29
+ '[\\udc00-\\udfff]' ;
30
+
22
31
const escape_html_attr_regex = new RegExp (
23
- // special characters
24
- `[${ Object . keys ( escape_html_attr_dict ) . join ( '' ) } ]|` +
25
- // high surrogate without paired low surrogate
26
- '[\\ud800-\\udbff](?![\\udc00-\\udfff])|' +
27
- // a valid surrogate pair, the only match with 2 code units
28
- // we match it so that we can match unpaired low surrogates in the same pass
29
- // TODO: use lookbehind assertions once they are widely supported: (?<![\ud800-udbff])[\udc00-\udfff]
30
- '[\\ud800-\\udbff][\\udc00-\\udfff]|' +
31
- // unpaired low surrogate (see previous match)
32
- '[\\udc00-\\udfff]' ,
32
+ `[${ Object . keys ( escape_html_attr_dict ) . join ( '' ) } ]|` + surrogates ,
33
33
'g'
34
34
) ;
35
35
36
36
const escape_html_regex = new RegExp (
37
- // special characters
38
- `[${ Object . keys ( escape_html_dict ) . join ( '' ) } ]|` +
39
- // high surrogate without paired low surrogate
40
- '[\\ud800-\\udbff](?![\\udc00-\\udfff])|' +
41
- // a valid surrogate pair, the only match with 2 code units
42
- // we match it so that we can match unpaired low surrogates in the same pass
43
- // TODO: use lookbehind assertions once they are widely supported: (?<![\ud800-udbff])[\udc00-\udfff]
44
- '[\\ud800-\\udbff][\\udc00-\\udfff]|' +
45
- // unpaired low surrogate (see previous match)
46
- '[\\udc00-\\udfff]' ,
37
+ `[${ Object . keys ( escape_html_dict ) . join ( '' ) } ]|` + surrogates ,
47
38
'g'
48
39
) ;
49
40
0 commit comments