]> Cypherpunks repositories - gostls13.git/commit
exp/template/html: normalize '<' in text and RCDATA nodes.
authorMike Samuel <mikesamuel@gmail.com>
Sun, 18 Sep 2011 19:04:40 +0000 (12:04 -0700)
committerMike Samuel <mikesamuel@gmail.com>
Sun, 18 Sep 2011 19:04:40 +0000 (12:04 -0700)
commit52a46bb77352bd911a478d870acb7453234c52f3
treed5521ec0377c8232f1f1f033a70e402312f59b37
parente213a0c0fcd51f43d38b9423561989ed0b9e616c
exp/template/html: normalize '<' in text and RCDATA nodes.

The template

  <{{.}}

would violate the structure preservation property if allowed and not
normalized, because when {{.}} emitted "", the "<" would be part of
a text node, but if {{.}} emitted "a", the "<" would not be part of
a text node.

This change rewrites '<' in text nodes and RCDATA text nodes to
'&lt;' allowing template authors to write the common, and arguably more
readable:

    Your price: {{.P1}} < list price {{.P2}}

while preserving the structure preservation property.

It also lays the groundwork for comment elision, rewriting

    Foo <!-- comment with secret project details --> Bar

to

    Foo  Bar

R=nigeltao
CC=golang-dev
https://golang.org/cl/5043043
src/pkg/exp/template/html/escape.go
src/pkg/exp/template/html/escape_test.go