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..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') @@ -43,7 +44,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"'