YAML 1.1 Pair, Key is `y`, get parsed to `true` (bool)
sharky98 opened this issue · 2 comments
Describe the bug
When parsing a Unity YAML file, one object is defined with key-value pairs, including one with a y
in it (like in X,Y coordinates). When parsed, the key is transformed to a boolean true
.
To Reproduce
Using the Playground, parse the following YAML
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!213 &21300000
Sprite:
m_Rect:
x: 0
y: 128
width: 128
height: 128
gives the following result:
[
Pair {
key: Scalar { value: 'x', range: [Array], source: 'x', type: 'PLAIN' },
value: Scalar { value: 0, range: [Array], source: '0', type: 'PLAIN' }
},
Pair {
key: Scalar { value: true, range: [Array], source: 'y', type: 'PLAIN' },
value: Scalar { value: 128, range: [Array], source: '128', type: 'PLAIN' }
},
Pair {
key: Scalar { value: 'width', range: [Array], source: 'width', type: 'PLAIN' },
value: Scalar { value: 128, range: [Array], source: '128', type: 'PLAIN' }
},
Pair {
key: Scalar { value: 'height', range: [Array], source: 'height', type: 'PLAIN' },
value: Scalar { value: 128, range: [Array], source: '128', type: 'PLAIN' }
}
]
Expected behaviour
The key of a key-value pair, should not be transformed according to the boolean rule.
Versions (please complete the following information):
- Environment: Node 22.8.0
yaml
: 2.5.1
Additional context
I found the schema used, but I have no clues where it get used when parsing the key.
TIL, this is by design for YAML 1.1 that the keys are parsed like anything else. Damn YAML is complex!
https://ruudvanasseldonk.com/2023/01/11/the-yaml-document-from-hell#non-string-keys
Yeah, this seems to be an uncomfortably common stumbling block. It might make sense to add an option like stringKeys
to enforce their parsing as such.