Skip to content

Conversation

@thevilledev
Copy link
Contributor

@thevilledev thevilledev commented Jan 5, 2026

Why the changes in this PR are needed?

When a template string expression contains an undeclared variable, the compiler was reporting the internal rewritten variable name (e.g., __local2__) instead of the original variable name. This is described in issue #8157.

What are the changes in this PR?

The rewrite map RewrittenVars is now passed through template string rewriting functions. The rewritten variable names are translated back to original names when errors are being generated.

There actually was a test case already for this marked with FIXME. The test is now fixed and I also added a regression test from #8157.

Notes to assist PR review:

The RewriteLocalVars compiler stage runs before RewriteTemplateStrings, so variables have already been renamed to internal names by the time template string safety checks run. The fix follows the same pattern used elsewhere like in safetyErrorSlice and checkSafetyRuleHeads.

Further comments:

Fixes #8157.

Undeclared variable errors in template string expressions were showing
internal rewritten variable names (e.g., "__local2__") instead of the
original names. Pass RewrittenVars map to template string rewriting
functions to translate error messages back to user-visible names.

Signed-off-by: Ville Vesilehto <[email protected]>
@netlify
Copy link

netlify bot commented Jan 5, 2026

Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit f34918a
🔍 Latest deploy log https://app.netlify.com/projects/openpolicyagent/deploys/695bff39abcf150008a562b9
😎 Deploy Preview https://deploy-preview-8180--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.

@thevilledev thevilledev marked this pull request as ready for review January 5, 2026 18:24
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.

🎉 Thank you!

@srenatus srenatus merged commit b2e4c94 into open-policy-agent:main Jan 5, 2026
31 checks passed
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.

Rewritten var name leaked from unsafe template string expression

2 participants