From: Andrew Gerrand Date: Fri, 21 Sep 2012 19:54:36 +0000 (+1000) Subject: [release-branch.go1] text/template/parse: fix bug handling /*/ X-Git-Tag: go1.0.3~93 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=d3f4ba0c71b1e5e80d2c7f316a2e15ed32abff09;p=gostls13.git [release-branch.go1] text/template/parse: fix bug handling /*/ --- 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.