Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

html/template: predefined escaper "html" disallowed in template with no "html" #20323

Closed
bep opened this issue May 11, 2017 · 2 comments
Closed
Milestone

Comments

@bep
Copy link
Contributor

bep commented May 11, 2017

On current tip

package tpl

import (
	"bytes"
	"html/template"
	"testing"
)

func TestDisallowedEscaper(t *testing.T) {
	data := map[string]string{
		"html": "<h1>Hi!</h1>",
	}

	tpl := `{{ .html | print }}`

	var buf bytes.Buffer
	tmpl, err := template.New("").Parse(tpl)
	if err != nil {
		t.Fatal(err)
	}
	if err := tmpl.Execute(&buf, data); err != nil {
		t.Fatal(err)
	}

	if buf.String() != `&lt;h1&gt;Hi!&lt;/h1&gt;` {
		t.Fatalf("Got %q", buf.String())
	}

}

Fails with

predefined escaper "html" disallowed in template
FAIL

This was probably introduced as a fix to #19952 -- and while I do understand the motivation behind the error in that issue, the above example is obviously correct and should just work.

Also note that even if the above example looks constructed, the error comes from a real world application. Having a JSON property named html is common enough in the wild, Twitter and Instagram being two examples.

gohugoio/hugo#3454

@ianlancetaylor ianlancetaylor added this to the Go1.9 milestone May 11, 2017
@ianlancetaylor
Copy link
Contributor

CC @stjj89

@gopherbot
Copy link

CL https://golang.org/cl/43296 mentions this issue.

@golang golang locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants