From d3f4ba0c71b1e5e80d2c7f316a2e15ed32abff09 Mon Sep 17 00:00:00 2001 From: Andrew Gerrand Date: Sat, 22 Sep 2012 05:54:36 +1000 Subject: [PATCH] [release-branch.go1] text/template/parse: fix bug handling /*/ --- src/pkg/text/template/parse/lex.go | 5 +++-- src/pkg/text/template/parse/lex_test.go | 4 ++++ 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. -- 2.50.0