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

std.parseYaml processes "on" as a boolean #766

Open
Duologic opened this issue Aug 29, 2024 · 2 comments
Open

std.parseYaml processes "on" as a boolean #766

Duologic opened this issue Aug 29, 2024 · 2 comments

Comments

@Duologic
Copy link

I noticed this on go-jsonnet but couldn't replicate with the C or rust version:

➜ cat a.yaml
on: help

➜ jsonnet -e 'std.parseYaml(importstr "a.yaml")'
{
   "true": "help"
}

➜ cjsonnet -e 'std.parseYaml(importstr "a.yaml")'
{
   "on": "help"
}

➜ jrsonnet -e 'std.parseYaml(importstr "a.yaml")'
{
   "on": "help"
}
@CertainLach
Copy link

In theory, golang behavior is correct, as in yaml, keys may not only be strings, but any object

However, as Jsonnet only allows strings as object keys, in Rust implementation I explicitly deserialize object keys as strings (thus skipping all of yaml magic), matching cjsonnet behavior (cjsonnet transforms rapidyaml output to json first, again deserializing object keys as strings), thus resulting in "on" key, instead of deserializing object key as anything (boolean in this case) and then coercing it to string (toString(true)).

Golang's behavior also brings problem with numbers:
0o11: 1 == "9": 1
...Including golang-specific (But implemented in jrsonnet) octals: google/jsonnet#1109
011: 1 == "9": 1
Even uglier problems with booleans:
n: 1 == "false": 1
And note that null also fails:
null: 1 == error

The solution for all of that is to not rely on yaml implementation in specific language, instead explicitly quote all the keys that might confuse the parser.

@hairyhenderson
Copy link

on is not a boolean in YAML (at least, not in the latest YAML spec), so this behaviour should be considered incorrect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants