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

yq doesn't preserve previous document settings when parsing multiple YAML 1.1 documents in the same stream #1900

Open
normanr opened this issue Dec 12, 2023 · 0 comments
Labels

Comments

@normanr
Copy link

normanr commented Dec 12, 2023

Describe the bug
It looks like Tag Shorthands are not preserved when processing multiple documents when the subsequent documents do not have any directives. If I repeat the directives for subsequent documents (or expand Tag Shorthands into Verbatim Tags), then yq parses the stream correctly.

Version of yq: 4.16.2
Operating system: linux
Installed via: git clone & dpkg-buildpackage

Input Yaml
This doesn't work
data1.yml:

%YAML 1.1
%TAG !e! tag:example.com:
--- !e!1
Thing:
  foo: 1
--- !e!2
Widget:
  bar: 2

but this does:
data2.yml:

%YAML 1.1
%TAG !e! tag:example.com:
--- !e!1
Thing:
  foo: 1
%TAG !e! tag:example.com:
--- !e!2
Widget:
  bar: 2

and so does this:

%YAML 1.1
--- !<tag:example.com:1>
Thing:
  foo: 1
--- !<tag:example.com:2>
Widget:
  bar: 2

Command
The command you ran:

yq eval data1.yml
yq eval-all data1.yml

Actual behavior

eval:

%YAML 1.1
!<tag:example.com:1>
Thing:
  foo: 1
Error: bad file 'data1.yaml': yaml: line 4: found undefined tag handle

eval-all:

Error: bad file 'data1.yaml': yaml: line 4: found undefined tag handle

Expected behavior

%YAML 1.1
!<tag:example.com:1>
Thing:
  foo: 1
---
!<tag:example.com:2>
Widget:
  bar: 2

Additional context
This seems to be a supported feature of YAML 1.1: "If the document specifies no directives, it is parsed using the same settings as the previous document.", but YAML 1.2 says: "Each document is completely independent from the rest.". It would be nice if the old 1.1 fallback was supported if possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant