jsonnet icon indicating copy to clipboard operation
jsonnet copied to clipboard

std.parseYaml() parses quoted numbers as numbers

Open vincentmrg opened this issue 1 year ago • 4 comments

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

vincentmrg avatar Mar 06 '23 15:03 vincentmrg

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

sparkprime avatar Mar 06 '23 16:03 sparkprime

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

vincentmrg avatar Mar 06 '23 16:03 vincentmrg

It's probably a bug in RapidYAML then

sparkprime avatar Mar 06 '23 16:03 sparkprime

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

johnbartholomew avatar Feb 09 '24 17:02 johnbartholomew

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

johnbartholomew avatar Feb 27 '24 13:02 johnbartholomew