index.js 650 B

1234567891011121314151617
  1. 'use strict';
  2. var assert = require('assert');
  3. var stringify = require('../');
  4. assert(stringify('foo') === '"foo"');
  5. assert(stringify('foo\u2028bar\u2029baz') === '"foo\\u2028bar\\u2029baz"');
  6. assert(stringify(new Date('2014-12-19T03:42:00.000Z')) === 'new Date("2014-12-19T03:42:00.000Z")');
  7. assert(stringify({foo: 'bar'}) === '{"foo":"bar"}');
  8. assert(stringify(undefined) === 'undefined');
  9. assert(stringify(null) === 'null');
  10. assert(
  11. stringify({val: "</script><script>alert('bad actor')</script>"}) ===
  12. '{"val":"\\u003C\\u002Fscript\\u003E\\u003Cscript\\u003Ealert(\'bad actor\')\\u003C\\u002Fscript\\u003E"}'
  13. );
  14. console.log('tests passed');