Skip to content

Commit 579546a

Browse files
committed
dry
1 parent 092aa91 commit 579546a

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

packages/kit/src/utils/escape.js

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,22 @@ const escape_html_dict = {
1919
'<': '&lt;'
2020
};
2121

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+
2231
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,
3333
'g'
3434
);
3535

3636
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,
4738
'g'
4839
);
4940

0 commit comments

Comments
 (0)