Last active
December 5, 2017 20:10
-
-
Save dougrich/f5dc109a6695436684e47c25f3bf6fa0 to your computer and use it in GitHub Desktop.
Bug reproduction for fast-json-stringify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Node version: v8.0.0 | |
// fast-json-stringify-version version: 0.15.1 | |
// Windows 10, 64 bit | |
const fastJson = require('fast-json-stringify'); | |
const goodSchema = { | |
title: 'Example Schema', | |
type: 'object', | |
properties: { | |
nickname: { | |
$ref: 'strings#' | |
} | |
}, | |
patternProperties: { | |
'num': { | |
$ref: 'numbers#/definitions/num' | |
} | |
} | |
} | |
const badSchema = { | |
title: 'Example Schema', | |
type: 'object', | |
properties: { | |
nickname: { | |
// note that the hash is omitted from this; this is valid JSON schema | |
// see: https://spacetelescope.github.io/understanding-json-schema/structuring.html#the-id-property | |
$ref: 'strings' | |
} | |
}, | |
patternProperties: { | |
'num': { | |
$ref: 'numbers#/definitions/num' | |
} | |
} | |
} | |
const externalSchema = { | |
numbers: { | |
definitions: { | |
num: { | |
type: 'object', | |
properties: { | |
int: { | |
type: 'integer' | |
} | |
} | |
} | |
} | |
}, | |
strings: { | |
type: 'string' | |
} | |
} | |
// this works as expected | |
const stringify = fastJson(goodSchema, { schema: externalSchema }) | |
// this crashes | |
const stringify = fastJson(schema, { schema: externalSchema }) | |
/* | |
## crash log | |
<path>\fast-json-stringify-issue>node ./index.js | |
<path>\fast-json-stringify-issue\node_modules\fast-json-stringify\index.js:354 | |
var walk = ref[1].split('/') | |
^ | |
TypeError: Cannot read property 'split' of undefined | |
at refFinder (<path>\fast-json-stringify-issue\node_modules\fast-json-stringify\index.js:354:20) | |
at Object.keys.forEach (<path>\fast-json-stringify-issue\node_modules\fast-json-stringify\index.js:387:32) | |
at Array.forEach (native) | |
at buildObject (<path>\fast-json-stringify-issue\node_modules\fast-json-stringify\index.js:377:40) | |
at build (<path>\fast-json-stringify-issue\node_modules\fast-json-stringify\index.js:58:14) | |
at Object.<anonymous> (<path>\fast-json-stringify-issue\index.js:36:19) | |
at Module._compile (module.js:569:30) | |
at Object.Module._extensions..js (module.js:580:10) | |
at Module.load (module.js:503:32) | |
at tryModuleLoad (module.js:466:12) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment