google / jsonnet

Jsonnet - The data templating language
http://jsonnet.org
Apache License 2.0
6.92k stars 437 forks source link

std.parseYaml() parses quoted numbers as numbers #1050

Closed vincentmrg closed 6 months ago

vincentmrg commented 1 year ago

Hello,

It looks like the std.parseYaml function parses quoted numbers as numbers (instead of string). e.g.

bash-5.1$ cat test.jsonnet 
local yaml = 'id: "91372278466"\nname: staging\n';
std.parseYaml(yaml)
bash-5.1$ jsonnet test.jsonnet 
{
   "id": 91372278466,
   "name": "staging"
}

Another unexpected behavior is that this function fails if said number starts with a 0. e.g.

bash-5.1$ cat test.jsonnet 
local yaml = 'id: "091372278466"\nname: staging\n';
std.parseYaml(yaml)
bash-5.1$ jsonnet test.jsonnet 
Something went wrong during jsonnet_evaluate_snippet, please report this: [json.exception.parse_error.101] parse error at line 1, column 19: syntax error while parsing object - unexpected number literal; expected '}'
Abort trap: 6
sparkprime commented 1 year ago

I'm guessing this is an issue with the underlying parser? Was it C++ or Go

vincentmrg commented 1 year ago

It was with the C++ version. I just tested with the go implementation, it works fine.

sparkprime commented 1 year ago

It's probably a bug in RapidYAML then

johnbartholomew commented 7 months ago

This one should be fixed by #1134 (upgrading RapidYAML to 0.5.0)

johnbartholomew commented 6 months ago

Should work on master now. I have added a test case for it (#1136). Thanks for the bug report!