Skip to content

Commit 1e14710

Browse files
committed
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 <[email protected]> Reviewed-by: Paul Jolly <[email protected]>
1 parent 13a4d3c commit 1e14710

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

internal/third_party/yaml/decode.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import (
1212
"strconv"
1313
"strings"
1414
"time"
15-
"unicode"
1615

1716
"cuelang.org/go/cue/ast"
1817
"cuelang.org/go/cue/literal"
1918
"cuelang.org/go/cue/token"
19+
"cuelang.org/go/internal"
2020
)
2121

2222
const (
@@ -539,24 +539,9 @@ func (d *decoder) scalar(n *node) ast.Expr {
539539
}
540540

541541
func (d *decoder) label(n *node) ast.Label {
542-
var tag string
543-
if n.tag == "" && !n.implicit {
544-
tag = yaml_STR_TAG
545-
} else {
546-
tag, _ = d.resolve(n)
547-
}
548-
if tag == yaml_STR_TAG {
549-
// TODO: improve
550-
for i, r := range n.value {
551-
if !unicode.In(r, unicode.L) && r != '_' {
552-
if i == 0 || !unicode.In(r, unicode.N) {
553-
goto stringLabel
554-
}
555-
}
556-
}
542+
if ast.IsValidIdent(n.value) && !internal.IsDefOrHidden(n.value) {
557543
return d.ident(n, n.value)
558544
}
559-
stringLabel:
560545
return &ast.BasicLit{
561546
ValuePos: d.start(n),
562547
Kind: token.STRING,

internal/third_party/yaml/decode_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,15 @@ var unmarshalTests = []struct {
154154
}, {
155155
"english: null",
156156
"english: null",
157+
}, {
158+
"_foo: 1",
159+
`"_foo": 1`,
160+
}, {
161+
`"#foo": 1`,
162+
`"#foo": 1`,
163+
}, {
164+
"_#foo: 1",
165+
`"_#foo": 1`,
157166
}, {
158167
"~: null key",
159168
`"~": "null key"`,

0 commit comments

Comments
 (0)