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

Error on optional string escapes in input, even though valid in JSON #984

Open
chaimleib opened this issue Oct 27, 2021 · 3 comments
Open
Labels

Comments

@chaimleib
Copy link

Describe the bug
According to the JSON spec (YAML is a superset of JSON), YAML 1.2.2, and YAML 1.3.0, "\/" is valid string syntax, equivalent to "/".

However, when "\/" exists on the input to yq, the escaped character is not recognized.

Version of yq: 4.13.3
Operating system: mac
Installed via: go install github.com/mikefarah/yq/v4@v4.13.3 under go1.17.2 darwin/amd64

Input

test.yml

["\/"]

Command
The command you ran:

yq e '.[0]' test.yml

Actual behavior

Error: yaml: found unknown escape character

Expected behavior

/

Additional context

Optional escapes on input strings work fine with jq-1.6:

% jq -r '.[0]' test.yml
/
@mikefarah
Copy link
Owner

This is an issue with the underlying go-yaml parser - please raise the issue there: https://github.com/go-yaml/yaml

FWIW I created a playground example of your bug: https://play.golang.org/p/QNulMRqLfVx

@chaimleib
Copy link
Author

Thanks! I created an issue there:
go-yaml/yaml/issues/797

@balki
Copy link

balki commented Jun 24, 2024

Ran into this issue today. When yq knows the input is json, it works correctly.

❯ cat one.json         
{
    "foo":"App\/3.2.7"
}
❯ yq one.json
{
  "foo": "App/3.2.7"
}
❯ cat one.json | yq   
Error: bad file '-': yaml: line 2: found unknown escape character
❯ cat one.json | yq -pj
foo: App/3.2.7

Looks like upstream go-yaml has been abandoned. @mikefarah Any plans to do move to different yaml lib or maintain a fork ?

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

3 participants