Skip to content

Conversation

@anderseknert
Copy link
Member

Escaping { only at the time of serializtion, which should help avoid special case treatment of these string values. But if there is a better approach I haven't thought of, let me know.

Fixes #8156

@netlify
Copy link

netlify bot commented Dec 25, 2025

Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit b782fa5
🔍 Latest deploy log https://app.netlify.com/projects/openpolicyagent/deploys/6952f5ef5da6860008c86120
😎 Deploy Preview https://deploy-preview-8161--openpolicyagent.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

v1/ast/term.go Outdated

errFindNotFound = errors.New("find: not found")

unescapedLeftCurly = regexp.MustCompile(`([^\\])({)`)
Copy link
Contributor

@srenatus srenatus Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why capture? Should this not be the same?

Suggested change
unescapedLeftCurly = regexp.MustCompile(`([^\\])({)`)
unescapedLeftCurly = regexp.MustCompile(`[^\\]{`)

Hmm looking at this without the (), it does look kind of ambiguous. Is that why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That'll give Expected "unescaped \\{ left curly brace." but got "unescaped\\{ left curly brace."

i.e. space removed for reasons I didn't care enough about to find out about. I don't like the regex thing either, so I'll see if I can get something else to work.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out both solutions were flawed, as they would not escape a curly brace at position 0 in a string. Will cook something better up tonight.

Copy link
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda feel like we don't need a regex to find a { not preceded by a \. 🤔 But I suppose you have considered alternatives already.

@anderseknert
Copy link
Member Author

@srenatus it was 3 AM, and went with the first thing I could think of. I'll see if there's something cheaper.

Escaping `{` only at the time of serializtion, which should help
avoid special case treatment of these string values. But if there
is a better approach I haven't thought of, let me know.

Fixes open-policy-agent#8156

Signed-off-by: Anders Eknert <[email protected]>
@anderseknert anderseknert force-pushed the templatestrings-esc-brace branch from 328e2fc to b782fa5 Compare December 29, 2025 21:43
@anderseknert
Copy link
Member Author

@srenatus sorry about the delay.. turns out there is little time for coding when you are alone with two kids. I have just pushed an updated version that doesn't use a regular expression, and while it performs much better, it's more importantly correct. At least for any case I managed to come up with. PTAL, so that we can bump our Regal OPA dep and have a release first thing in the new year 🙂

Copy link
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@anderseknert anderseknert merged commit b06737b into open-policy-agent:main Dec 30, 2025
31 checks passed
@anderseknert anderseknert deleted the templatestrings-esc-brace branch December 30, 2025 23:05
sspaink pushed a commit to sspaink/opa that referenced this pull request Jan 5, 2026
…t#8161)

Escaping `{` only at the time of serializtion, which should help
avoid special case treatment of these string values. But if there
is a better approach I haven't thought of, let me know.

Fixes open-policy-agent#8156

Signed-off-by: Anders Eknert <[email protected]>
(cherry picked from commit b06737b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

opa fmt removes escapes, breaking string interpolation

2 participants