Skip to content

Commit

Permalink
Merge pull request #17 from commenthol/empty_string
Browse files Browse the repository at this point in the history
Empty string
  • Loading branch information
commenthol committed Jan 31, 2020
2 parents f84f1b8 + 68b51fe commit 2949f8a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion test/index.test.js
Expand Up @@ -36,14 +36,16 @@ 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')
test('number negative float', -0.2, '-0.2')
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',
'<script type="application/javascript">\u2028\u2029\nvar a = 0;\nvar b = 1; a > 1;\n</script>',
'"\\u003Cscript type=\\"application\\u002Fjavascript\\"\\u003E\\u2028\\u2029\\nvar a = 0;\\nvar b = 1; a \\u003E 1;\\n\\u003C\\u002Fscript\\u003E"'
Expand Down

0 comments on commit 2949f8a

Please sign in to comment.