mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-30 22:39:58 +02:00
tpl: Pull in Go 1.18 patch that fixes the "no space in {{ continue }} and {{ break }}" bug
This commit is contained in:
@@ -45,7 +45,7 @@ func escapeTemplate(tmpl *Template, node parse.Node, name string) error {
|
||||
}
|
||||
|
||||
// evalArgs formats the list of arguments into a string. It is equivalent to
|
||||
// fmt.Sprint(args...), except that it deferences all pointers.
|
||||
// fmt.Sprint(args...), except that it dereferences all pointers.
|
||||
func evalArgs(args ...any) string {
|
||||
// Optimization for simple common case of a single string argument.
|
||||
if len(args) == 1 {
|
||||
@@ -691,7 +691,7 @@ func (e *escaper) escapeTemplateBody(c context, t *template.Template) (context,
|
||||
return c.eq(c1)
|
||||
}
|
||||
// We need to assume an output context so that recursive template calls
|
||||
// take the fast path out of escapeTree instead of infinitely recursing.
|
||||
// take the fast path out of escapeTree instead of infinitely recurring.
|
||||
// Naively assuming that the input context is the same as the output
|
||||
// works >90% of the time.
|
||||
e.output[t.Name()] = c
|
||||
|
@@ -415,8 +415,8 @@ func (t *Tree) action() (n Node) {
|
||||
// {{break}}
|
||||
// Break keyword is past.
|
||||
func (t *Tree) breakControl(pos Pos, line int) Node {
|
||||
if token := t.next(); token.typ != itemRightDelim {
|
||||
t.unexpected(token, "in {{break}}")
|
||||
if token := t.nextNonSpace(); token.typ != itemRightDelim {
|
||||
t.unexpected(token, "{{break}}")
|
||||
}
|
||||
if t.rangeDepth == 0 {
|
||||
t.errorf("{{break}} outside {{range}}")
|
||||
@@ -428,8 +428,8 @@ func (t *Tree) breakControl(pos Pos, line int) Node {
|
||||
// {{continue}}
|
||||
// Continue keyword is past.
|
||||
func (t *Tree) continueControl(pos Pos, line int) Node {
|
||||
if token := t.next(); token.typ != itemRightDelim {
|
||||
t.unexpected(token, "in {{continue}}")
|
||||
if token := t.nextNonSpace(); token.typ != itemRightDelim {
|
||||
t.unexpected(token, "{{continue}}")
|
||||
}
|
||||
if t.rangeDepth == 0 {
|
||||
t.errorf("{{continue}} outside {{range}}")
|
||||
|
@@ -263,6 +263,10 @@ var parseTests = []parseTest{
|
||||
{"newline in pipeline", "{{\n\"x\"\n|\nprintf\n}}", noError, `{{"x" | printf}}`},
|
||||
{"newline in comment", "{{/*\nhello\n*/}}", noError, ""},
|
||||
{"newline in comment", "{{-\n/*\nhello\n*/\n-}}", noError, ""},
|
||||
{"spaces around continue", "{{range .SI}}{{.}}{{ continue }}{{end}}", noError,
|
||||
`{{range .SI}}{{.}}{{continue}}{{end}}`},
|
||||
{"spaces around break", "{{range .SI}}{{.}}{{ break }}{{end}}", noError,
|
||||
`{{range .SI}}{{.}}{{break}}{{end}}`},
|
||||
|
||||
// Errors.
|
||||
{"unclosed action", "hello{{range", hasError, ""},
|
||||
|
Reference in New Issue
Block a user