std.parseYaml fails on non-standard yaml feature, supported in other implementations
- Dominant language
- Jsonnet
- Stars
- 7.6k
- Forks
- 475
- PR merge metrics
- No merged PRs in 30d
Description
Consider this input:
```jsonnet
std.parseYaml("0777")
```
cpp-jsonnet outputs:
```
Something went wrong during jsonnet_evaluate_snippet, please report this: [json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing array - unexpected number literal; expected ']'
Segmentation fault
```
go-jsonnet outputs:
```
511
```
jrsonnet outputs:
```
511
```
sjsonnet outputs:
```
sjsonnet.Error: Internal error: scala.MatchError: null
Caused by: scala.MatchError: null
```
But this is caused by sjsonnet only supporting objects in parseYaml, so `std.parseYaml("a: 0777")` works:
```
{
"a": 511
}
```
Why does it happens?
Well, there is two yaml specs: yaml 1.1, and yaml 1.2, and even if it is a minor update by semver... It isn't a semver.
The one breaking change in yaml 1.2, is that octal literals in `0777` form are now forbidden, `0o777` should be used instead.
However, many yaml implementations are not following the spec, especially golang, which will even output octals in `0777` format: https://github.com/go-yaml/yaml/issues/420
For jrsonnet, I had to modify serde-yaml rust library to also accept this input: https://github.com/dtolnay/serde-yaml/pull/225
And rapidyaml did not implemented this compatibility feature: https://github.com/biojppm/rapidyaml/issues/291
Contributor guide
Assessment
This issue has not been assessed yet.