From c067f34558b82455b63b9ce8f5983b4b4849c7cf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Fri, 29 Dec 2017 09:52:43 +0100 Subject: [PATCH] tpl/transform: Do not unescape input to highlight Fixes #4179 --- tpl/transform/transform.go | 2 +- tpl/transform/transform_test.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tpl/transform/transform.go b/tpl/transform/transform.go index a94cc46e..7ec1fec0 100644 --- a/tpl/transform/transform.go +++ b/tpl/transform/transform.go @@ -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 } diff --git a/tpl/transform/transform_test.go b/tpl/transform/transform_test.go index 429b206f..195a0f15 100644 --- a/tpl/transform/transform_test.go +++ b/tpl/transform/transform_test.go @@ -69,6 +69,8 @@ func TestHighlight(t *testing.T) { expect interface{} }{ {"func boo() {}", "go", "", "boo"}, + // Issue #4179 + {``, "xml", "", `<`}, {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) } } -- 2.30.2