Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YAML decoder does not handle aliases in map keys #3821

Open
OmriSteiner opened this issue Mar 16, 2025 · 0 comments · May be fixed by #3822
Open

YAML decoder does not handle aliases in map keys #3821

OmriSteiner opened this issue Mar 16, 2025 · 0 comments · May be fixed by #3822

Comments

@OmriSteiner
Copy link

What version of CUE are you using (cue version)?

$ cue version
cue version v0.12.0

go version go1.23.7
      -buildmode exe
       -compiler gc
  DefaultGODEBUG asynctimerchan=1,gotypesalias=0,httpservecontentkeepheaders=1,tls3des=1,tlskyber=0,x509keypairleaf=0,x509negativeserial=1
     CGO_ENABLED 1
          GOARCH amd64
            GOOS linux
         GOAMD64 v1
cue.lang.version v0.12.0

Does this issue reproduce with the latest stable release?

Yes, and also from main.

What did you do?

cue import my.yaml

Where my.yaml is:

foo: &foo "hello"
*foo : "world"

What did you expect to see?

Cue successfully imports the YAML as:

foo: "hello"
hello: "world"

What did you see instead?

invalid map key: !!str

Note that in old versions (e.g 0.8.2) this wouldn't error out, but rather emit this cue file, which is incorrect:

foo: "hello"
foo: "world"

This is probably a bug in the old YAML decoder (before migrating to yaml.v3)

@OmriSteiner OmriSteiner added NeedsInvestigation Triage Requires triage/attention labels Mar 16, 2025
OmriSteiner added a commit to OmriSteiner/cue that referenced this issue Mar 16, 2025
This makes the decoder follow aliases in YAML map keys.
Before this commit the decoder would outright reject these keys as
non-scalar keys. This commit adds support specifically for keys which
are aliases to scalar values. YAML also permits non-scalar keys such as
maps / sequences, but there's no equivalent for those in CUE, so we
error out.

fixes cue-lang#3821

Signed-off-by: Omri Steiner <[email protected]>
@mvdan mvdan added encoding and removed Triage Requires triage/attention labels Mar 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants