Repository navigation
Support escaping a GSP expression with a backslash \${} - #16144
Merged
jdaugherty merged 1 commit intoAug 13, 2026
Merged
Conversation
\${...} in template text now renders a literal ${...} instead of being
evaluated: the scanner leaves the escaped sequence in the surrounding
HTML token and the parser drops the backslash when writing it out.
Escaping is resolved at parse time, before code generation, so all
compilation modes behave identically and escaped text is invisible to
static compilation. The primary use is JavaScript template literals,
whose interpolation placeholders share the ${...} syntax.
Only the backslash performing the escape is removed, each expression
must be escaped individually, and expressions in tag attributes cannot
be escaped this way.
Also adds the junit-jupiter-engine test runtime dependency that
grails-gsp-core was missing: the module declared only the Jupiter API,
so the JUnit Platform silently skipped its Jupiter test classes,
including all of GroovyPagesTemplateEngineTests.
Claude-Session: https://claude.ai/code/session_01WtCxMe9pfmy7tiHCUr5THN
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 8.0.x #16144 +/- ##
==================================================
+ Coverage 52.5503% 52.6414% +0.0911%
- Complexity 18391 18436 +45
==================================================
Files 2037 2037
Lines 96498 96500 +2
Branches 16860 16860
==================================================
+ Hits 50710 50799 +89
+ Misses 38353 38272 -81
+ Partials 7435 7429 -6
🚀 New features to boost your workflow:
|
codeconsole
requested review from
borinquenkid,
jamesfredley,
jdaugherty,
matrei and
sbglasius
and removed request for
jdaugherty
August 13, 2026 01:42
JS Template \${var}
JS Template \${var}
✅ All tests passed ✅🏷️ Commit: daaa404 Learn more about TestLens at testlens.app. |
sbglasius
approved these changes
Aug 13, 2026
matrei
reviewed
Aug 13, 2026
jdaugherty
approved these changes
Aug 13, 2026
Contributor
|
@codeconsole I had merged this before seeing @matrei comment. can you please update the upgrade section? |
This was referenced Nov 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A backslash immediately before a GSP expression now escapes it:
\${...}renders a literal${...}with the backslash removed, instead of the expression being evaluated on the server.GSP previously had no escape syntax at all —
\${x}rendered a stray\followed by the evaluated expression. The motivating case is JavaScript template literals, whose interpolation placeholders share the${}syntax and are today either evaluated against the page binding (an unbound name silently renders as empty) or blow up the whole page render:The browser now receives the template literal with its
${name}placeholder intact, to be interpolated by JavaScript.Implementation
Escaping is resolved entirely at parse time, in two small pieces:
GroovyPageScannerno longer starts an expression token when the${is immediately preceded by a backslash in template text — the sequence stays in the surrounding HTML token.GroovyPageParser.html()rewrites\${to${when writing the HTML token out.Because this happens before code generation, behavior is identical in development, production, and
compileStaticmodes, and escaped text is invisible to static type checking — an escaped${undeclaredName}under<%@ page compileStatic="true" %>neither fails compilation nor evaluates (covered by a new test inGspCompileStaticSpec).Semantics
\\${x}renders\${x}.Also in this PR
grails-gsp-coredeclaredjunit-jupiter-apibut never the Jupiter engine, so the JUnit Platform silently skipped every Jupiter-annotated test class in the module — all ofGroovyPagesTemplateEngineTests(23 tests) never ran. Added the repo-standardtestRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'; all resurrected tests pass. The other engine-less modules with Jupiter tests (grails-gsp/plugin,grails-gsp/grails-taglib) receive the engine transitively and were already running them.Tests and docs
ScanTests: escaped${stays in the HTML token; unescaped expressions still tokenize; mixed escaped/unescaped side by side.GroovyPagesTemplateEngineTests: literal render, escaped next to evaluated, JavaScript template literal end-to-end, double-backslash semantics.GspCompileStaticSpec: escaped expressions are invisible to static compilation.Full
:grails-gsp-core:testand:grails-gsp:testsuites plus downstream:grails-taglib,:grails-sitemesh3,:grails-layout, and:grails-web-gspall pass;codeStyleis clean on the touched modules.https://claude.ai/code/session_01WtCxMe9pfmy7tiHCUr5THN