Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
internal/third_party/yaml: fix faulty decoding of hidden fields
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
mpvl committed May 19, 2021
1 parent 13a4d3c commit 1e14710
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
19 changes: 2 additions & 17 deletions internal/third_party/yaml/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
"strconv"
"strings"
"time"
"unicode"

"cuelang.org/go/cue/ast"
"cuelang.org/go/cue/literal"
"cuelang.org/go/cue/token"
"cuelang.org/go/internal"
)

const (
Expand Down Expand Up @@ -539,24 +539,9 @@ func (d *decoder) scalar(n *node) ast.Expr {
}

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,
Expand Down
9 changes: 9 additions & 0 deletions internal/third_party/yaml/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@ var unmarshalTests = []struct {
}, {
"english: null",
"english: null",
}, {
"_foo: 1",
`"_foo": 1`,
}, {
`"#foo": 1`,
`"#foo": 1`,
}, {
"_#foo: 1",
`"_#foo": 1`,
}, {
"~: null key",
`"~": "null key"`,
Expand Down

0 comments on commit 1e14710

Please sign in to comment.