tpl/transform: Do not unescape input to highlight
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 29 Dec 2017 08:52:43 +0000 (09:52 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 29 Dec 2017 08:52:43 +0000 (09:52 +0100)
Fixes #4179

tpl/transform/transform.go
tpl/transform/transform_test.go

index a94cc46e2bc7ab65e6f04d58ae62bd914ab75e12..7ec1fec0205ce779365428aa83b2d3307590641a 100644 (file)
@@ -55,7 +55,7 @@ func (ns *Namespace) Highlight(s interface{}, lang, opts string) (template.HTML,
                return "", err
        }
 
-       highlighted, _ := ns.deps.ContentSpec.Highlight(html.UnescapeString(ss), lang, opts)
+       highlighted, _ := ns.deps.ContentSpec.Highlight(ss, lang, opts)
        return template.HTML(highlighted), nil
 }
 
index 429b206fd1f2a215b8efc351d6d62ff5730d86c8..195a0f15c9ee2d281e13a29b33bd20f4f78e99e6 100644 (file)
@@ -69,6 +69,8 @@ func TestHighlight(t *testing.T) {
                expect interface{}
        }{
                {"func boo() {}", "go", "", "boo"},
+               // Issue #4179
+               {`<Foo attr=" &lt; "></Foo>`, "xml", "", `&amp;lt;`},
                {tstNoStringer{}, "go", "", false},
        } {
                errMsg := fmt.Sprintf("[%d]", i)
@@ -81,7 +83,7 @@ func TestHighlight(t *testing.T) {
                }
 
                require.NoError(t, err, errMsg)
-               assert.Contains(t, result, "boo", errMsg)
+               assert.Contains(t, result, test.expect.(string), errMsg)
        }
 }