Skip to content

Commit

Permalink
internal/third_party/yaml: drop support for non-standard scalars
Browse files Browse the repository at this point in the history
CUE uses a mix of YAML packages. The older one in third_party/yaml
recognizes boolean scalars such as `y` and `n` that the newer package
does not quote, so round-tripping fails when those unquoted strings
get converted to booleans.

Fix this (pending replacement of the whole package) by removing support for those scalars.

Fixes cuelang/cue#512

Change-Id: I3958664a24a3191f0d3004b259ae26d2db86d0b5
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/7161
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
rogpeppe authored and mpvl committed Sep 30, 2020
1 parent 1fdc02a commit 1c29042
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
23 changes: 23 additions & 0 deletions cmd/cue/cmd/testdata/script/issue512.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cue export -o bools.yaml bools.cue
cue import -o bools2.cue bools.yaml
cmp bools.cue bools2.cue

-- bools.cue --
x: [
"n",
"N",
"no",
"No",
"NO",
"y",
"Y",
"yes",
"Yes",
"YES",
"off",
"Off",
"OFF",
"on",
"On",
"ON",
]
2 changes: 1 addition & 1 deletion cmd/cue/cmd/testdata/script/vet_file.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ translations:
---
translations:
hello:
lang: no
lang: false
text: Hallo
---
translations:
Expand Down
14 changes: 10 additions & 4 deletions internal/third_party/yaml/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,22 @@ var unmarshalTests = []struct {
// Bools from spec
{
"canonical: y",
"canonical: true",
`canonical: "y"`,
}, {
"answer: n",
`answer: "n"`,
}, {
"answer: NO",
"answer: false",
`answer: "NO"`,
}, {
"logical: True",
"logical: true",
}, {
"option: on",
"option: true",
`option: "on"`,
}, {
"answer: off",
`answer: "off"`,
},
// Ints from spec
{
Expand Down Expand Up @@ -243,7 +249,7 @@ apple: "newline"`,
"a: [1, 2]",
}, {
"a: y",
"a: true",
`a: "y"`,
}, {
"{ a: 1, b: {c: 1} }",
`a: 1, b: {c: 1}`,
Expand Down
6 changes: 1 addition & 5 deletions internal/third_party/yaml/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func init() {
for _, c := range "0123456789" {
t[int(c)] = 'D' // Digit
}
for _, c := range "yYnNtTfFoO~" {
for _, c := range "nNtTfF~" {
t[int(c)] = 'M' // In map
}
t[int('.')] = '.' // Float (potentially in map)
Expand All @@ -34,12 +34,8 @@ func init() {
tag string
l []string
}{
{true, yaml_BOOL_TAG, []string{"y", "Y", "yes", "Yes", "YES"}},
{true, yaml_BOOL_TAG, []string{"true", "True", "TRUE"}},
{true, yaml_BOOL_TAG, []string{"on", "On", "ON"}},
{false, yaml_BOOL_TAG, []string{"n", "N", "no", "No", "NO"}},
{false, yaml_BOOL_TAG, []string{"false", "False", "FALSE"}},
{false, yaml_BOOL_TAG, []string{"off", "Off", "OFF"}},
{nil, yaml_NULL_TAG, []string{"", "~", "null", "Null", "NULL"}},
{math.NaN(), yaml_FLOAT_TAG, []string{".nan", ".NaN", ".NAN"}},
{math.Inf(+1), yaml_FLOAT_TAG, []string{".inf", ".Inf", ".INF"}},
Expand Down

0 comments on commit 1c29042

Please sign in to comment.