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

Cannot regex match parentheses after the implementation of string interpolation feature in 4.43.1 #2083

Open
DMaxter opened this issue Jun 25, 2024 · 2 comments
Labels

Comments

@DMaxter
Copy link

DMaxter commented Jun 25, 2024

Describe the bug
When handling regex matching with yq, if we want to match against a parentheses, it is not possible. We always get this error about unclosed interpolation string

Version of yq: >= 4.43.1
Operating system: Linux
Installed via: binary release

Input Yaml
data.yml:

- name: abc
- name: d(ef)

Command
The command you ran:

 yq '.[] | select(.name | test("d\(ef\)"))' data.yml # Works with version 4.42.1 and previous
 yq --string-interpolation '.[] | select(.name | test("d\(ef\)"))' data.yml # Only possible after 4.43.1 but doesn't work, output is the same

Actual behavior

Error: unclosed interpolation string \(

Expected behavior

name: d(ef)

Additional context
I think the string interpolation feature is not working well, regex matching is greatly affected here

@mikefarah
Copy link
Owner

Hey, yep that's a bug.
You can turn off string-interpolation using that flag though, you just need to set it to false:

yq --string-interpolation=f '.[] | select(.name | test("d\(ef\)"))' examples/data1.yaml

That said, I'll fix the bug so when a unclosed interpolation is detected, it will skip interpolation (and log a warning) instead of aborting.

@DMaxter
Copy link
Author

DMaxter commented Jun 29, 2024

Is there any usecase where we want string interpolation inside regex matches? I mean, we can always do test("something " + .property + " another something"), right?

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

2 participants