• Mike Samuel's avatar
    exp/template/html: normalize '<' in text and RCDATA nodes. · 52a46bb7
    Mike Samuel authored
    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
    52a46bb7
escape.go 18.2 KB