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

Double-quote parsing during string interpolation differs from jq #2142

Open
kanaka opened this issue Sep 5, 2024 · 1 comment
Open

Double-quote parsing during string interpolation differs from jq #2142

kanaka opened this issue Sep 5, 2024 · 1 comment
Labels

Comments

@kanaka
Copy link

kanaka commented Sep 5, 2024

Describe the bug

Version of yq: 4.44.3
Operating system: ubuntu 24.04
Installed via: curl

Input Yaml
data1.yml:

data:
  - "abc"
  - "def"

data1.json:

{"data":["abc","def"]}

Command
The command you ran:

yq '"\(.data | join(" "))"' ./data1.yml

Actual behavior

Error: bad expression, please check expression syntax

Expected behavior

"abc def"

Additional context
Using jq on the json of the same data works fine:

$ jq '"\(.data | join(" "))"' ./data1.json
"abc def"

Also, escaping the inner double quotes will make it work in yq, but it will break in jq. I suspect this means that the yq parsing of strings is looking for the first unescaped double-quote in the string but it should be skipping any double-quotes that are within interpolation sections \(....).

@kanaka
Copy link
Author

kanaka commented Sep 5, 2024

Looks like the problem is here:

{"QuotedStringValue", `"([^"\\]*(\\.[^"\\]*)*)"`, stringValue(), 0},

I don't think pure regex will be able to handle parsing interpolated strings because you will need to keep track of the paren wrapping depth of commands inside of interpolation blocks, i.e. I believe something like this is legal syntax in jq: "prefix\(func1(func2(func3("blah"))))suffix"

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