diff --git a/src/schema/core/float.ts b/src/schema/core/float.ts index eaac883b..fad731a9 100644 --- a/src/schema/core/float.ts +++ b/src/schema/core/float.ts @@ -6,7 +6,7 @@ export const floatNaN: ScalarTag = { identify: value => typeof value === 'number', default: true, tag: 'tag:yaml.org,2002:float', - test: /^(?:[-+]?\.(?:inf|Inf|INF|nan|NaN|NAN))$/, + test: /^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/, resolve: str => str.slice(-3).toLowerCase() === 'nan' ? NaN diff --git a/src/schema/yaml-1.1/float.ts b/src/schema/yaml-1.1/float.ts index 19e54a5b..87e52b63 100644 --- a/src/schema/yaml-1.1/float.ts +++ b/src/schema/yaml-1.1/float.ts @@ -6,7 +6,7 @@ export const floatNaN: ScalarTag = { identify: value => typeof value === 'number', default: true, tag: 'tag:yaml.org,2002:float', - test: /^[-+]?\.(?:inf|Inf|INF|nan|NaN|NAN)$/, + test: /^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/, resolve: (str: string) => str.slice(-3).toLowerCase() === 'nan' ? NaN diff --git a/tests/doc/types.ts b/tests/doc/types.ts index 7646f303..31658aa3 100644 --- a/tests/doc/types.ts +++ b/tests/doc/types.ts @@ -373,19 +373,22 @@ option: TruE\n`) const src = `canonical: 6.8523015e+5 fixed: 685230.15 negative infinity: -.inf -not a number: .NaN` +not a number: .NaN +not a NaN: -.NaN` const doc = parseDocument(src) expect(doc.toJS()).toMatchObject({ canonical: 685230.15, fixed: 685230.15, 'negative infinity': Number.NEGATIVE_INFINITY, - 'not a number': NaN + 'not a number': NaN, + 'not a NaN': '-.NaN' }) expect(String(doc)).toBe(`canonical: 6.8523015e+5 fixed: 685230.15 negative infinity: -.inf -not a number: .nan\n`) +not a number: .nan +not a NaN: -.NaN\n`) }) test('!!int', () => { @@ -546,7 +549,8 @@ exponential: 685.230_15e+03 fixed: 685_230.15 sexagesimal: 190:20:30.15 negative infinity: -.inf -not a number: .NaN` +not a number: .NaN +not a NaN: -.NaN` const doc = parseDocument(src) expect(doc.toJS()).toMatchObject({ @@ -555,7 +559,8 @@ not a number: .NaN` fixed: 685230.15, sexagesimal: 685230.15, 'negative infinity': Number.NEGATIVE_INFINITY, - 'not a number': NaN + 'not a number': NaN, + 'not a NaN': '-.NaN' }) expect(String(doc)).toBe(`%YAML 1.1 --- @@ -564,7 +569,8 @@ exponential: 6.8523015e+5 fixed: 685230.15 sexagesimal: 190:20:30.15 negative infinity: -.inf -not a number: .nan\n`) +not a number: .nan +not a NaN: -.NaN\n`) }) test('!!int', () => {