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

@std/yaml parses yaml with anchor wrong #4792

Closed
taind772 opened this issue May 21, 2024 · 2 comments
Closed

@std/yaml parses yaml with anchor wrong #4792

taind772 opened this issue May 21, 2024 · 2 comments
Labels
bug Something isn't working PR welcome A pull request for this issue would be welcome yaml

Comments

@taind772
Copy link

Describe the bug

import * as yaml from "jsr:@std/yaml@0.224.0"

const sample = `
test: &test
    a: 2
    b: 4
    c: 6
another:
    <<: *test
    c: 8
    d: 10
`
console.log(yaml.parse(sample))

Steps to Reproduce

❯ deno run yaml-test.ts
{
  test: { a: 2, b: 4, c: 6 },
  another: { "0": undefined, "1": undefined, "2": undefined, c: 8, d: 10 }
}

Expected behavior

echo "
  test: &test
      a: 2
      b: 4
      c: 6
  another:
      <<: *test
      c: 8
      d: 10
  " | yq -o json
{
  "test": {
    "a": 2,
    "b": 4,
    "c": 6
  },
  "another": {
    "a": 2,
    "b": 4,
    "c": 8,
    "d": 10
  }
}

Environment

  • OS: Linux / Arch
  • deno version: 1.43.3
  • std version: 0.224
@taind772 taind772 added bug Something isn't working needs triage labels May 21, 2024
@taind772
Copy link
Author

I think the wrong part is merging.
Support or not, the output doesn't make sense to me at all. If merging is not supported, at least we should return something like

{
  test: { a: 2, b: 4, c: 6 },
  another: { "<<": { a: 2, b: 4, c: 6 }, c: 8, d: 10 }
}

I found a workaround (for my use case) by using https://www.npmjs.com/package/yaml instead:

import * as yaml from "npm:yaml"

const sample = `
test: &test
    a: 2
    b: 4
    c: 6
another:
    <<: *test
    c: 8
    d: 10
`
console.log(yaml.parse(sample, { merge: true }))

@kt3k kt3k removed the needs triage label May 23, 2024
@iuioiua iuioiua added yaml PR welcome A pull request for this issue would be welcome labels May 24, 2024
@babiabeo
Copy link
Contributor

This issue has been fixed by #5185.

@iuioiua iuioiua closed this as completed Aug 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working PR welcome A pull request for this issue would be welcome yaml
Projects
None yet
Development

No branches or pull requests

4 participants