google / google/jsonnet

std.parseYaml fails on non-standard yaml feature, supported in other implementations

Open
#1,109 3 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.