aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Gerrand <adg@golang.org>2012-09-22 05:54:36 +1000
committerAndrew Gerrand <adg@golang.org>2012-09-22 05:54:36 +1000
commitd3f4ba0c71b1e5e80d2c7f316a2e15ed32abff09 (patch)
tree1a0f955288668b3f21c4b8e97d42bfe246543ef7
parent43bf5e8ec8039f740cb4f6589eea736c96a0bdf4 (diff)
downloadgo-d3f4ba0c71b1e5e80d2c7f316a2e15ed32abff09.tar.gz
go-d3f4ba0c71b1e5e80d2c7f316a2e15ed32abff09.zip
[release-branch.go1] text/template/parse: fix bug handling /*/
-rw-r--r--src/pkg/text/template/parse/lex.go5
-rw-r--r--src/pkg/text/template/parse/lex_test.go4
2 files changed, 7 insertions, 2 deletions
diff --git a/src/pkg/text/template/parse/lex.go b/src/pkg/text/template/parse/lex.go
index 7705c0b88f..c4e1a56a8d 100644
--- a/src/pkg/text/template/parse/lex.go
+++ b/src/pkg/text/template/parse/lex.go
@@ -257,16 +257,17 @@ func lexText(l *lexer) stateFn {
// lexLeftDelim scans the left delimiter, which is known to be present.
func lexLeftDelim(l *lexer) stateFn {
- if strings.HasPrefix(l.input[l.pos:], l.leftDelim+leftComment) {
+ l.pos += len(l.leftDelim)
+ if strings.HasPrefix(l.input[l.pos:], leftComment) {
return lexComment
}
- l.pos += len(l.leftDelim)
l.emit(itemLeftDelim)
return lexInsideAction
}
// lexComment scans a comment. The left comment marker is known to be present.
func lexComment(l *lexer) stateFn {
+ l.pos += len(leftComment)
i := strings.Index(l.input[l.pos:], rightComment+l.rightDelim)
if i < 0 {
return l.errorf("unclosed comment")
diff --git a/src/pkg/text/template/parse/lex_test.go b/src/pkg/text/template/parse/lex_test.go
index 6ee1b47010..f3b23c91e4 100644
--- a/src/pkg/text/template/parse/lex_test.go
+++ b/src/pkg/text/template/parse/lex_test.go
@@ -198,6 +198,10 @@ var lexTests = []lexTest{
tRight,
tEOF,
}},
+ {"text with bad comment", "hello-{{/*/}}-world", []item{
+ {itemText, "hello-"},
+ {itemError, `unclosed comment`},
+ }},
}
// collect gathers the emitted items into a slice.