commit | 1399b52dc4a3cf5347603bf7011984cf28a34031 | [log] [tgz] |
---|---|---|
author | Daniel Martí <mvdan@mvdan.cc> | Sun Oct 28 16:23:00 2018 +0000 |
committer | Daniel Martí <mvdan@mvdan.cc> | Sun Oct 28 20:20:00 2018 +0000 |
tree | 8f9b397c37ba1f2e5102d136b0e529ccd7a7e4dc | |
parent | 81475ca256df3fdd281c0e656b4e743caacbc4e0 [diff] |
text/template/parse: error on bad range variables The package used to accept invalid range pipelines, such as: {{range $k, .}} {{range $k, 123 := .}} This is because the logic that allowed a range pipeline to declare multiple variables was broken. When encountering a single comma inside a range pipeline, it would happily continue parsing a second variable, even if we didn't have a variable token at all. Then, the loop would immediately break, and we'd parse the pipeline we'd be ranging over. That is, we'd parse {{range $k, .}} as if it were {{range $k = .}}. To fix this, only allow the loop to continue if we know we're going to parse another variable or a token that would end the pipeline. Also add a few test cases for these error edge cases. While at it, make use of T.Run, which was useful in debugging Tree.pipeline via print statements. Fixes #28437. Change-Id: Idc9966bf643f0f3bc1b052620357e5b0aa2022ea Reviewed-on: https://go-review.googlesource.com/c/145282 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> Reviewed-by: Rob Pike <r@golang.org>
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
Gopher image by Renee French, licensed under Creative Commons 3.0 Attributions license.
Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.
Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.
Official binary distributions are available at https://golang.org/dl/.
After downloading a binary release, visit https://golang.org/doc/install or load doc/install.html in your web browser for installation instructions.
If a binary distribution is not available for your combination of operating system and architecture, visit https://golang.org/doc/install/source or load doc/install-source.html in your web browser for source installation instructions.
Go is the work of thousands of contributors. We appreciate your help!
To contribute, please read the contribution guidelines: https://golang.org/doc/contribute.html
Note that the Go project uses the issue tracker for bug reports and proposals only. See https://golang.org/wiki/Questions for a list of places to ask questions about the Go language.