diff --git a/src/index.ts b/src/index.ts index 7d7e41c..ad0bd13 100644 --- a/src/index.ts +++ b/src/index.ts @@ -66,7 +66,7 @@ function stringifyString (string: string): string { // eslint-disable-next-line no-control-regex return '"' + string.replace(/[\\"\u0000-\u001F\u2028\u2029]/g, (m) => { if (escMap[m] !== undefined) return escMap[m] - return '\\u' + (m.charCodeAt(0) + 0x10000).toString(16).substr(1) + return '\\u' + (m.charCodeAt(0) + 0x10000).toString(16).slice(1) }) + '"' } diff --git a/test/index.test.ts b/test/index.test.ts index f72e6bc..851f807 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -119,8 +119,8 @@ describe('index.js', function () { it('should escape serialized strings', function () { const result: string = index(function (a: string, b: string) { return a + ' ' + b - }, 'foo"bar\\"\n', 'baz') - if (!result.includes(')("foo\\"bar\\\\\\"\\n", "baz")')) { + }, 'foo"bar\\"\n-\u0000\u2028\u2029\u0007', 'baz') + if (!result.includes(')("foo\\"bar\\\\\\"\\n-\\u0000\\u2028\\u2029\\u0007", "baz")')) { throw new Error('incorrect serialization: ' + result) } })