]> Cypherpunks repositories - gostls13.git/commitdiff
text/template/parse: mostly roll back the error detection for unmatched right delimiters
authorRob Pike <r@golang.org>
Fri, 13 Sep 2013 02:44:45 +0000 (12:44 +1000)
committerRob Pike <r@golang.org>
Fri, 13 Sep 2013 02:44:45 +0000 (12:44 +1000)
It's too late to change this behavior: it breaks templates with minimized JavaScript.

Makes me sad because this common error can never be caught: "{foo}}".
Three cheers for compatibility.

(Leave in a fix to a broken test.)

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

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

index 690497d645a683127febfeeb09b3d65fc73b842e..1674aaf9cd4bb63a42c0bee5aa833875bc5ec81a 100644 (file)
@@ -217,10 +217,6 @@ func lexText(l *lexer) stateFn {
                        }
                        return lexLeftDelim
                }
-               // Check for right after left in case they're the same.
-               if strings.HasPrefix(l.input[l.pos:], l.rightDelim) {
-                       return l.errorf("unmatched right delimiter")
-               }
                if l.next() == eof {
                        break
                }
index e72e07f26963855b8c0515d04e57d43c433dd67c..d251ccffb6c002cfa30f84669f9254b7c70373dc 100644 (file)
@@ -340,8 +340,11 @@ var lexTests = []lexTest{
                {itemText, 0, "hello-"},
                {itemError, 0, `comment ends before closing delimiter`},
        }},
+       // This one is an error that we can't catch because it breaks templates with
+       // minimized JavaScript. Should have fixed it before Go 1.1.
        {"unmatched right delimiter", "hello-{.}}-world", []item{
-               {itemError, 0, `unmatched right delimiter`},
+               {itemText, 0, "hello-{.}}-world"},
+               tEOF,
        }},
 }