diff --git a/src/json.ts b/src/json.ts index 44883991..4bf6a68e 100644 --- a/src/json.ts +++ b/src/json.ts @@ -397,9 +397,10 @@ function nextJSONToken(_state: JSONStreamState, _out: JSONToken): boolean { } } while (true); - _out.value = source.substring(_out.offset + 1, pos - 1).replace(/\\u([0-9A-Fa-f]{4})/g, (_, m0) => { - return (String).fromCodePoint(parseInt(m0, 16)); - }).replace(/\\(.)/g, (_, m0) => { + _out.value = source.substring(_out.offset + 1, pos - 1).replace(/\\(?:u([0-9A-Fa-f]{4})|(.))/g, (_, hex, m0) => { + if (hex) { + return (String).fromCodePoint(parseInt(hex, 16)); + } switch (m0) { case '"': return '"'; case '\\': return '\\'; diff --git a/src/tests/json.test.ts b/src/tests/json.test.ts index 8ecc1bfb..c76ef6f9 100644 --- a/src/tests/json.test.ts +++ b/src/tests/json.test.ts @@ -68,6 +68,8 @@ test('JSON Strings', function () { isValid('["string"]'); isValid('["\\"\\\\\\/\\b\\f\\n\\r\\t\\u1234\\u12AB"]'); isValid('["\\\\"]'); + isValid('["\\\\A\\\\u200B"]'); + isValid('["\\u005cn"]'); isInvalid('["'); isInvalid('["]');