Skip to content

if YAML contains anchors, path.Replace fails with "invalid query" #298

Open
@marco-m

Description

@marco-m

Hello,

consider the following new test case added to TestPath_Replace:

{
    path: "$.a.a1",
    dst: `
a: &a-anchor
  a1: foo
b: *a-anchor
`,
    src: `bar`,
    expected: `
a: &a-anchor
  a1: bar
b: *a-anchor
`,

it fails with a long stacktrace for the 3 subtests "WithReader", "WithFile" and "WithNode". Here is a shortened version:

=== RUN   TestPath_Replace/$.a.a1/WithNode
    path_test.go:578: failed to replace node by path ( $.a.a1 ):
            github.com/goccy/go-yaml.(*Path).ReplaceWithNode
          - failed to replace:
            github.com/goccy/go-yaml.(*rootNode).replace
          - failed to replace map value:
            github.com/goccy/go-yaml.(*selectorNode).replace
          - failed to replace:
            github.com/goccy/go-yaml.(*selectorNode).replaceMapValue
          - expected node type is map or map value. but got Anchor:
            github.com/goccy/go-yaml.(*selectorNode).replace
          - invalid query:
            github.com/goccy/go-yaml.init

I have a partial fix, but the problem is that somehow some newlines are not printed. See PR #299.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingyamlpath

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions