-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
20 lines (17 loc) · 850 Bytes
/
index.js
File metadata and controls
20 lines (17 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
'use strict';
var assert = require('assert');
var stringify = require('../');
assert(stringify('foo') === '"foo"');
assert(stringify('foo\u2028bar\u2029baz') === '"foo\\u2028bar\\u2029baz"');
assert(stringify(new Date('2014-12-19T03:42:00.000Z')) === 'new Date("2014-12-19T03:42:00.000Z")');
assert(stringify({foo: 'bar'}) === '{"foo":"bar"}');
assert(stringify({foo: 'bar'}, undefined) === '{"foo":"bar"}');
assert(stringify({foo: 'bar'}, 3) === '{\n "foo": "bar"\n}');
assert(stringify({foo: 'bar'}, ' \t') === '{\n \t"foo": "bar"\n}');
assert(stringify(undefined) === 'undefined');
assert(stringify(null) === 'null');
assert(
stringify({val: "</script><script>alert('bad actor')</script>"}) ===
'{"val":"\\u003C\\u002Fscript\\u003E\\u003Cscript\\u003Ealert(\'bad actor\')\\u003C\\u002Fscript\\u003E"}'
);
console.log('tests passed');