]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1] text/template/parse: fix bug handling /*/
authorAndrew Gerrand <adg@golang.org>
Fri, 21 Sep 2012 19:54:36 +0000 (05:54 +1000)
committerAndrew Gerrand <adg@golang.org>
Fri, 21 Sep 2012 19:54:36 +0000 (05:54 +1000)
src/pkg/text/template/parse/lex.go
src/pkg/text/template/parse/lex_test.go

index 7705c0b88ff8c0051620b5efd4af69ee7bbcc2f0..c4e1a56a8d41789fb46cc997f187011a3ebf1855 100644 (file)
@@ -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")
index 6ee1b47010284925ac11b7405392d0fc82e3cbf9..f3b23c91e43a7384547d94b21e0f6a777790cc41 100644 (file)
@@ -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.