Skip to content

html/template: set division context when a template literal closes - #81190

Open
harjothkhara wants to merge 1 commit into
golang:masterfrom
harjothkhara:oss-find/go-2026-08-27
Open

html/template: set division context when a template literal closes#81190
harjothkhara wants to merge 1 commit into
golang:masterfrom
harjothkhara:oss-find/go-2026-08-27

Conversation

@harjothkhara

Copy link
Copy Markdown
Contributor

A '/' that follows a JavaScript template literal starts a division,
not a regexp literal, but tJSTmpl left jsCtx unchanged when it saw
the closing backtick. The context stayed jsCtxRegexp from when the
literal opened, so a template action after the literal was escaped
as regexp text and its value was written without quotes:

<script>let x = `a`/{{.}}/b;</script>

executed with the value "alert1" produced

<script>let x = `a`/alert`1`/b;</script>

Set jsCtx to jsCtxDivOp when the closing backtick is reached, the
same way tJSDelimited does when a JS string or regexp closes.

Fixes #81117

A '/' that follows a JavaScript template literal starts a division,
not a regexp literal, but tJSTmpl left jsCtx unchanged when it saw
the closing backtick. The context stayed jsCtxRegexp from when the
literal opened, so a template action after the literal was escaped
as regexp text and its value was written without quotes:

  <script>let x = `a`/{{.}}/b;</script>

executed with the value "alert`1`" produced

  <script>let x = `a`/alert`1`/b;</script>

Set jsCtx to jsCtxDivOp when the closing backtick is reached, the
same way tJSDelimited does when a JS string or regexp closes.

Fixes golang#81117
@harjothkhara
harjothkhara marked this pull request as ready for review August 28, 2026 05:47
@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: a341fec) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/823564.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Gopher Robot:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/823564.
After addressing review feedback, remember to publish your drafts!

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.

html/template: JS context is not reset when template literal closes

2 participants