Skip to content

Commit 8b5d363

Browse files
committed
Merge branch 'master' of github.com:Rich-Harris/devalue
2 parents 858e985 + 83e6a56 commit 8b5d363

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ export function stringify_string(str) {
6363
result += '\\"';
6464
} else if (char in escaped) {
6565
result += escaped[char];
66+
} else if (code <= 0x001F) {
67+
result += `\\u${code.toString(16).toUpperCase().padStart(4, "0")}`
6668
} else if (code >= 0xd800 && code <= 0xdfff) {
6769
const next = str.charCodeAt(i + 1);
6870

test/test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,18 @@ const fixtures = {
200200
js: '"\\u0000"',
201201
json: '["\\u0000"]'
202202
},
203+
{
204+
name: 'control character',
205+
value: '\u0001',
206+
js: '"\\u0001"',
207+
json: '["\\u0001"]'
208+
},
209+
{
210+
name: 'control character extremum',
211+
value: '\u001F',
212+
js: '"\\u001F"',
213+
json: '["\\u001F"]'
214+
},
203215
{
204216
name: 'backslash',
205217
value: '\\',

0 commit comments

Comments
 (0)