fast-json-stringify 5.14.0 → 5.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -438,7 +438,7 @@ function cloneOriginSchema (context, schema, schemaId) {
438
438
  for (const key in schema) {
439
439
  let value = schema[key]
440
440
 
441
- if (key === '$ref' && value.charAt(0) === '#') {
441
+ if (key === '$ref' && typeof value === 'string' && value.charAt(0) === '#') {
442
442
  value = schemaId + value
443
443
  }
444
444
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-json-stringify",
3
- "version": "5.14.0",
3
+ "version": "5.14.1",
4
4
  "description": "Stringify your JSON at max speed",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
@@ -717,3 +717,39 @@ test('external recursive allOfs', (t) => {
717
717
  const stringify = build(schema, { schema: { externalSchema } })
718
718
  t.equal(stringify(data), '{"a":{"bar":"42","foo":{}},"b":{"bar":"42","foo":{}}}')
719
719
  })
720
+
721
+ test('do not crash with $ref prop', (t) => {
722
+ t.plan(1)
723
+
724
+ const schema = {
725
+ title: 'object with $ref',
726
+ type: 'object',
727
+ properties: {
728
+ outside: {
729
+ $ref: '#/$defs/outside'
730
+ }
731
+ },
732
+ $defs: {
733
+ inside: {
734
+ type: 'object',
735
+ properties: {
736
+ $ref: {
737
+ type: 'string'
738
+ }
739
+ }
740
+ },
741
+ outside: {
742
+ allOf: [{
743
+ $ref: '#/$defs/inside'
744
+ }]
745
+ }
746
+ }
747
+ }
748
+ const stringify = build(schema)
749
+ const value = stringify({
750
+ outside: {
751
+ $ref: 'true'
752
+ }
753
+ })
754
+ t.equal(value, '{"outside":{"$ref":"true"}}')
755
+ })