Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # 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 · 4 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?

@mikefarah
Copy link
Owner

Fixed in 4.44.3

tmeijn pushed a commit to tmeijn/dotfiles that referenced this issue Aug 10, 2024
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [mikefarah/yq](https://github.com/mikefarah/yq) | patch | `v4.44.2` -> `v4.44.3` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>mikefarah/yq (mikefarah/yq)</summary>

### [`v4.44.3`](https://github.com/mikefarah/yq/releases/tag/v4.44.3)

[Compare Source](mikefarah/yq@v4.44.2...v4.44.3)

-   Fixed upper-case file extension detection, Thanks [@&#8203;ryenus](https://github.com/ryenus) ([#&#8203;2121](mikefarah/yq#2121))
    -   Log printing follow no-colors flag [#&#8203;2082](mikefarah/yq#2082)
    -   Skip and warn when interpolating strings and theres a unclosed bracket [#&#8203;2083](mikefarah/yq#2083)
    -   Fixed CSV content starting with # issue [#&#8203;2076](mikefarah/yq#2076)
    -   Bumped dependencies

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM3LjQ0MC43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
@DMaxter
Copy link
Author

DMaxter commented Aug 15, 2024

Seems to be working on my end. Thank you

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

No branches or pull requests

2 participants