Skip to content

Alias dereferincing between documents #328

@ccoVeille

Description

@ccoVeille

go-yaml accepts cross-document alias references, which the YAML spec forbids (anchors are scoped to a single document).

We should detect at go-yaml level if it's relevant
Originally posted by @ccoVeille in mikefarah/yq#2647 (comment)

It's confirmed by

https://yaml.org/spec/1.2.2/#91-documents

A YAML character stream may contain several documents. Each document is completely independent from the rest.

I tried with go-yaml

$ cat /tmp/alias-bug.yaml
---
&foo 42
---
*foo
$ ./go-yaml -t /tmp/alias-bug.yaml
- {token: STREAM-START}
- {token: DOCUMENT-START}
- {token: ANCHOR, value: foo}
- {token: SCALAR, value: 42}
- {token: DOCUMENT-START}
- {token: ALIAS, value: foo}
- {token: STREAM-END}
$ ./go-yaml -y /tmp/alias-bug.yaml
42
---
42

the bug is confirmed

We should report to something like this

$ ./go-yaml -y /tmp/alias-bug.yaml
42
Failed to process YAML:failed to decode YAML: go-yaml load error in composer at L4.C1: unknown anchor 'foo' referenced

Also, my IDE reported me this when I worked on the file I wanted to test 😄

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions