]> Cypherpunks repositories - gostls13.git/commit
html/template: track brace depth for each nested expression
authorRoland Shoemaker <roland@golang.org>
Thu, 5 Oct 2023 13:16:18 +0000 (06:16 -0700)
committerRoland Shoemaker <roland@golang.org>
Mon, 16 Oct 2023 03:29:27 +0000 (03:29 +0000)
commit5873bd1d7e87e0686390d71a840a44e2e2c3e11d
tree72b868931e29760efec9d0d0322e18da16beb9e8
parentbc9dc8d415fc1ecf8d0d63a01dd17b2b60bf4cf3
html/template: track brace depth for each nested expression

We need to track the brace depth for each individual nested expression,
since a string interpolation expression may be nested inside of an
object.

e.g. `${ {1:`${}`}}` has brace depths [1, 0] when inside of the inner
${} expression. When we exit the inner expression, we need to reset to
the previous brace depth (1) so that we know that the following } closes
the object, but not the outer expression.

Note that if you write a broken expression (i.e. `${ { }`) escaping will
clearly not work as expected (or depending on your interpretation, since
it is broken, it will work as expected). Since the JS parser doesn't
catch syntax errors, it's up to the user to write a valid template.

Updates #61619

Change-Id: I4c33723d12aff49facdcb1134d9ca82b7a0dffc4
Reviewed-on: https://go-review.googlesource.com/c/go/+/532995
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
src/html/template/context.go
src/html/template/escape_test.go
src/html/template/transition.go