From ed0dd61fda12d6acb13a83e7d5d7dbf16aa28fd4 Mon Sep 17 00:00:00 2001 From: commenthol Date: Fri, 31 Jan 2020 14:46:56 +0100 Subject: [PATCH 1/2] fix: empty string --- src/index.js | 2 +- test/index.test.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 60168f6..7143150 100644 --- a/src/index.js +++ b/src/index.js @@ -82,7 +82,7 @@ function serialize (source, opts = {}) { case 'Null': return 'null' case 'String': - return utils.quote(source, opts) + return utils.quote(source, opts) || '""' case 'Function': { const _tmp = source.toString() const tmp = opts.unsafe ? _tmp : utils.saferFunctionString(_tmp, opts) diff --git a/test/index.test.js b/test/index.test.js index 97b3923..e059ec2 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -43,7 +43,8 @@ describe('serialize-to-js', function () { test('NaN', NaN, 'NaN') test('Infinity', Infinity, 'Infinity') test('string', "string's\n\"new\" line", '"string\'s\\n\\"new\\" line"') - test('nul', '\0', '"\u0000"') + test('empty string', '', '""') + test('nul string', '\0', '"\u0000"') test('string with unsafe characters', '', '"\\u003Cscript type=\\"application\\u002Fjavascript\\"\\u003E\\u2028\\u2029\\nvar a = 0;\\nvar b = 1; a \\u003E 1;\\n\\u003C\\u002Fscript\\u003E"' From 68b51fe02ce06520f6d78cbc6b0a4e9bb06bf0a0 Mon Sep 17 00:00:00 2001 From: commenthol Date: Fri, 31 Jan 2020 14:48:12 +0100 Subject: [PATCH 2/2] test: zero --- test/index.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/index.test.js b/test/index.test.js index e059ec2..aa5f4a1 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -36,6 +36,7 @@ describe('serialize-to-js', function () { test('null', null, 'null') test('boolean', true, 'true') test('number', 3.1415, '3.1415') + test('zero', 0, '0') test('number int', 3, '3') test('number negative int', -13, '-13') test('number float', 0.1, '0.1')