internal/third_party/yaml: drop support for non-standard scalars
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 https://github.com/cuelang/cue/issues/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>
diff --git a/cmd/cue/cmd/testdata/script/issue512.txt b/cmd/cue/cmd/testdata/script/issue512.txt
new file mode 100644
index 0000000..dcbf80b
--- /dev/null
+++ b/cmd/cue/cmd/testdata/script/issue512.txt
@@ -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",
+]
diff --git a/cmd/cue/cmd/testdata/script/vet_file.txt b/cmd/cue/cmd/testdata/script/vet_file.txt
index c82374c..6f2f2a2 100644
--- a/cmd/cue/cmd/testdata/script/vet_file.txt
+++ b/cmd/cue/cmd/testdata/script/vet_file.txt
@@ -31,7 +31,7 @@
---
translations:
hello:
- lang: no
+ lang: false
text: Hallo
---
translations:
diff --git a/internal/third_party/yaml/decode_test.go b/internal/third_party/yaml/decode_test.go
index cd7f242..b6323e5 100644
--- a/internal/third_party/yaml/decode_test.go
+++ b/internal/third_party/yaml/decode_test.go
@@ -100,16 +100,22 @@
// 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
{
@@ -243,7 +249,7 @@
"a: [1, 2]",
}, {
"a: y",
- "a: true",
+ `a: "y"`,
}, {
"{ a: 1, b: {c: 1} }",
`a: 1, b: {c: 1}`,
diff --git a/internal/third_party/yaml/resolve.go b/internal/third_party/yaml/resolve.go
index bfe67c4..9699ada 100644
--- a/internal/third_party/yaml/resolve.go
+++ b/internal/third_party/yaml/resolve.go
@@ -24,7 +24,7 @@
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)
@@ -34,12 +34,8 @@
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"}},