internal/third_party/yaml: fix faulty decoding of hidden fields
Change-Id: Ib311a7c03caf08824bf16d16083940e80d5b6d18
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9841
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
diff --git a/internal/third_party/yaml/decode.go b/internal/third_party/yaml/decode.go
index a509c49..22fc6cb 100644
--- a/internal/third_party/yaml/decode.go
+++ b/internal/third_party/yaml/decode.go
@@ -12,11 +12,11 @@
"strconv"
"strings"
"time"
- "unicode"
"cuelang.org/go/cue/ast"
"cuelang.org/go/cue/literal"
"cuelang.org/go/cue/token"
+ "cuelang.org/go/internal"
)
const (
@@ -539,24 +539,9 @@
}
func (d *decoder) label(n *node) ast.Label {
- var tag string
- if n.tag == "" && !n.implicit {
- tag = yaml_STR_TAG
- } else {
- tag, _ = d.resolve(n)
- }
- if tag == yaml_STR_TAG {
- // TODO: improve
- for i, r := range n.value {
- if !unicode.In(r, unicode.L) && r != '_' {
- if i == 0 || !unicode.In(r, unicode.N) {
- goto stringLabel
- }
- }
- }
+ if ast.IsValidIdent(n.value) && !internal.IsDefOrHidden(n.value) {
return d.ident(n, n.value)
}
-stringLabel:
return &ast.BasicLit{
ValuePos: d.start(n),
Kind: token.STRING,
diff --git a/internal/third_party/yaml/decode_test.go b/internal/third_party/yaml/decode_test.go
index d08104e..c4d5cad 100644
--- a/internal/third_party/yaml/decode_test.go
+++ b/internal/third_party/yaml/decode_test.go
@@ -155,6 +155,15 @@
"english: null",
"english: null",
}, {
+ "_foo: 1",
+ `"_foo": 1`,
+ }, {
+ `"#foo": 1`,
+ `"#foo": 1`,
+ }, {
+ "_#foo: 1",
+ `"_#foo": 1`,
+ }, {
"~: null key",
`"~": "null key"`,
}, {