diff options
| author | Eli Bendersky <eliben@golang.org> | 2022-11-03 12:16:06 -0700 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2022-11-04 12:56:08 +0000 |
| commit | d65c0593c4f1dd4a9b381cf654668aa27166b24e (patch) | |
| tree | 3ba0cb0d0ad64441462a6c520aedac500558b283 /src/text/template/parse/parse.go | |
| parent | 90b40c0496440fbd57538eb4ba303164ed923d93 (diff) | |
| download | go-d65c0593c4f1dd4a9b381cf654668aa27166b24e.tar.xz | |
text/template/parse: fix interaction of break/continue keywords and functions
Fixes a bug that was introduced in CL 410414; in that CL, to avoid
a race condition in the initialization of the lexer, the setting
of the breakOK and continueOK options was moved to before
Tree.funcs was populated from parameters. As a result, the parser
missed the fact that 'break' and 'continue' were defined as functions.
Following CL 421883 race conditions are no longer an issue, so
the simplest fix is just to move the initialization where it was
before - in startParse, after t.funcs has been set.
Fixes #56538
Change-Id: I3b99fe9ad12255a4f6eb9a00eb3f64529ff055c0
Reviewed-on: https://go-review.googlesource.com/c/go/+/447775
Run-TryBot: Eli Bendersky <eliben@golang.org>
Auto-Submit: Eli Bendersky <eliben@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Eli Bendersky <eliben@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/text/template/parse/parse.go')
| -rw-r--r-- | src/text/template/parse/parse.go | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/text/template/parse/parse.go b/src/text/template/parse/parse.go index 87b7618f75..d43d5334ba 100644 --- a/src/text/template/parse/parse.go +++ b/src/text/template/parse/parse.go @@ -223,6 +223,11 @@ func (t *Tree) startParse(funcs []map[string]any, lex *lexer, treeSet map[string t.vars = []string{"$"} t.funcs = funcs t.treeSet = treeSet + lex.options = lexOptions{ + emitComment: t.Mode&ParseComments != 0, + breakOK: !t.hasFunction("break"), + continueOK: !t.hasFunction("continue"), + } } // stopParse terminates parsing. @@ -241,11 +246,6 @@ func (t *Tree) Parse(text, leftDelim, rightDelim string, treeSet map[string]*Tre defer t.recover(&err) t.ParseName = t.Name lexer := lex(t.Name, text, leftDelim, rightDelim) - lexer.options = lexOptions{ - emitComment: t.Mode&ParseComments != 0, - breakOK: !t.hasFunction("break"), - continueOK: !t.hasFunction("continue"), - } t.startParse(funcs, lexer, treeSet) t.text = text t.parse() |
