fast-json-stringify 5.13.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 +1 -1
- package/lib/serializer.js +10 -10
- package/package.json +3 -3
- package/test/allof.test.js +36 -0
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/lib/serializer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
// eslint-disable-next-line
|
|
4
|
-
const STR_ESCAPE = /[\u0000-\u001f\u0022\u005c\ud800-\udfff]
|
|
4
|
+
const STR_ESCAPE = /[\u0000-\u001f\u0022\u005c\ud800-\udfff]/
|
|
5
5
|
|
|
6
6
|
module.exports = class Serializer {
|
|
7
7
|
constructor (options) {
|
|
@@ -25,13 +25,12 @@ module.exports = class Serializer {
|
|
|
25
25
|
|
|
26
26
|
asInteger (i) {
|
|
27
27
|
if (typeof i === 'number') {
|
|
28
|
-
if (i === Infinity || i === -Infinity) {
|
|
29
|
-
throw new Error(`The value "${i}" cannot be converted to an integer.`)
|
|
30
|
-
}
|
|
31
28
|
if (Number.isInteger(i)) {
|
|
32
29
|
return '' + i
|
|
33
30
|
}
|
|
34
|
-
if
|
|
31
|
+
// check if number is Infinity or NaN
|
|
32
|
+
// eslint-disable-next-line no-self-compare
|
|
33
|
+
if (i === Infinity || i === -Infinity || i !== i) {
|
|
35
34
|
throw new Error(`The value "${i}" cannot be converted to an integer.`)
|
|
36
35
|
}
|
|
37
36
|
return this.parseInteger(i)
|
|
@@ -52,7 +51,9 @@ module.exports = class Serializer {
|
|
|
52
51
|
|
|
53
52
|
asNumber (i) {
|
|
54
53
|
const num = Number(i)
|
|
55
|
-
if
|
|
54
|
+
// check if number is NaN
|
|
55
|
+
// eslint-disable-next-line no-self-compare
|
|
56
|
+
if (num !== num) {
|
|
56
57
|
throw new Error(`The value "${i}" cannot be converted to a number.`)
|
|
57
58
|
} else if (!Number.isFinite(num)) {
|
|
58
59
|
return 'null'
|
|
@@ -128,10 +129,6 @@ module.exports = class Serializer {
|
|
|
128
129
|
// eslint-disable-next-line
|
|
129
130
|
for (var i = 0; i < len; i++) {
|
|
130
131
|
point = str.charCodeAt(i)
|
|
131
|
-
if (point < 32 || (point >= 0xD800 && point <= 0xDFFF)) {
|
|
132
|
-
// The current character is non-printable characters or a surrogate.
|
|
133
|
-
return JSON.stringify(str)
|
|
134
|
-
}
|
|
135
132
|
if (
|
|
136
133
|
point === 0x22 || // '"'
|
|
137
134
|
point === 0x5c // '\'
|
|
@@ -139,6 +136,9 @@ module.exports = class Serializer {
|
|
|
139
136
|
last === -1 && (last = 0)
|
|
140
137
|
result += str.slice(last, i) + '\\'
|
|
141
138
|
last = i
|
|
139
|
+
} else if (point < 32 || (point >= 0xD800 && point <= 0xDFFF)) {
|
|
140
|
+
// The current character is non-printable characters or a surrogate.
|
|
141
|
+
return JSON.stringify(str)
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fast-json-stringify",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.14.1",
|
|
4
4
|
"description": "Stringify your JSON at max speed",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
"simple-git": "^3.7.1",
|
|
47
47
|
"standard": "^17.0.0",
|
|
48
48
|
"tap": "^16.0.1",
|
|
49
|
-
"tsd": "^0.
|
|
49
|
+
"tsd": "^0.31.0",
|
|
50
50
|
"webpack": "^5.40.0",
|
|
51
51
|
"fast-json-stringify": "."
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"ajv": "^8.10.0",
|
|
55
|
-
"ajv-formats": "^
|
|
55
|
+
"ajv-formats": "^3.0.1",
|
|
56
56
|
"fast-deep-equal": "^3.1.3",
|
|
57
57
|
"fast-uri": "^2.1.0",
|
|
58
58
|
"rfdc": "^1.2.0",
|
package/test/allof.test.js
CHANGED
|
@@ -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
|
+
})
|