]> Cypherpunks repositories - gostls13.git/commitdiff
text/template/parse: fix bug handling /*/
authorRob Pike <r@golang.org>
Fri, 10 Aug 2012 02:24:46 +0000 (19:24 -0700)
committerRob Pike <r@golang.org>
Fri, 10 Aug 2012 02:24:46 +0000 (19:24 -0700)
Incorrect syntax for comment was erroneously accepted.
Fixes #3919.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6453105

src/pkg/text/template/parse/lex.go
src/pkg/text/template/parse/lex_test.go

index 443fb86423401ad559895efdfc1ace503ad08d8c..98f12a821fbff868ab3d4d67ac589fdd6615cd34 100644 (file)
@@ -264,16 +264,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")
index 842e92db21d2e745c4243a20369e7a85570349d2..f38057d8c367a8968789a0e5d5dc2efb66855036 100644 (file)
@@ -203,6 +203,10 @@ var lexTests = []lexTest{
                tRight,
                tEOF,
        }},
+       {"text with bad comment", "hello-{{/*/}}-world", []item{
+               {itemText, 0, "hello-"},
+               {itemError, 0, `unclosed comment`},
+       }},
 }
 
 // collect gathers the emitted items into a slice.