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

Support tag:yaml.org,2002:merge for parsing !!merge <<: &foo #579

Closed
dastrobu opened this issue Oct 2, 2024 · 0 comments · Fixed by #580
Closed

Support tag:yaml.org,2002:merge for parsing !!merge <<: &foo #579

dastrobu opened this issue Oct 2, 2024 · 0 comments · Fixed by #580
Labels
enhancement New feature or request

Comments

@dastrobu
Copy link

dastrobu commented Oct 2, 2024

Is your feature request related to a problem? Please describe.

In short, please add support for tag:yaml.org,2002:merge for parsing !!merge <<: &foo.

Parsing the following yaml

const YAML = require('yaml')

YAML.parse(`
      foo: &foo
       a: 1
       b: 2
      bar:
       !!merge <<: *foo
`, {merge: true})

results in a warning

 (node:28408) [TAG_RESOLVE_FAILED] YAMLWarning: Unresolved tag: tag:yaml.org,2002:merge at line 6, column 8:

      bar:
       !!merge <<: *foo
       ^^^^^^^

While

YAML.parse(`
      foo: &foo
       a: 1
       b: 2
      bar:
       <<: *foo
`, {merge: true}) 

works fine.

Describe the solution you'd like

Parsing works without warning.

Describe alternatives you've considered

My workaround is currently adding the following custom tag:

const YAML = require('yaml')

const mergeTag = {
  tag: 'tag:yaml.org,2002:merge',
  resolve(value) {
    return value;
  }
};

YAML.parse(`
      foo: &foo
       a: 1
       b: 2
      bar:
       !!merge <<: *foo
`, {merge: true, customTags: [mergeTag]})

which basically ignores the tag (if I am not mistaken).

Additional context

The problem came up, since yq is creating these tags automatically, when patching a yaml with a merge.
Here is an example

echo ' 
foo: &foo
  a: 1
  b: 2
bar:
   <<: *foo'  | 
yq '.foo.a |= "b"'

which results in

foo: &foo
  a: b
  b: 2
bar:
  !!merge <<: *foo

note the inserted !!merge.

@dastrobu dastrobu added the enhancement New feature or request label Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant