eemeli / yaml

YAML parser and stringifier for JavaScript
https://eemeli.org/yaml
ISC License
1.32k stars 116 forks source link

`[+-].nan` incorrectly supported? #546

Closed RedCMD closed 6 months ago

RedCMD commented 6 months ago

Describe the bug +.nan and -.nan are parsed as .nan

To Reproduce

+.nan: +.nan 
+.nan: +.nan
-.NaN: -.NaN
-.NaN: -.NaN
.NAN: .NAN
.NAN: .NAN

(Github correctly ignores [+-].nan, but also seems to interpret - as seq)

Expected behaviour [+-].nan should be parsed as type str

tag-resolution

Additional context also no error is given when multiple keys are given with the same value of type .nan

image image

eemeli commented 6 months ago

Not complaining about -.nan and +.nan is indeed a bug.

The lack of errors for multiple NaN keys is because NaN !== NaN in JavaScript, and === is what's used by uniqueKeys: true, the default. If this is important to you, it's possible to use e.g. a SameValueZero implementation as the uniqueKeys option value.