Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YAML 1.1 Pair, Key is y, get parsed to true (bool) #574

Closed
sharky98 opened this issue Sep 9, 2024 · 2 comments · Fixed by #581
Closed

YAML 1.1 Pair, Key is y, get parsed to true (bool) #574

sharky98 opened this issue Sep 9, 2024 · 2 comments · Fixed by #581
Labels
bug Something isn't working

Comments

@sharky98
Copy link

sharky98 commented Sep 9, 2024

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.

https://github.com/eemeli/yaml/blob/5adbb605b64094b57bc95cbc24587e6f36b3f9a8/src/schema/yaml-1.1/bool.ts

@sharky98 sharky98 added the bug Something isn't working label Sep 9, 2024
@sharky98
Copy link
Author

sharky98 commented Sep 9, 2024

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

@eemeli
Copy link
Owner

eemeli commented Sep 9, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants