reserved characters escaped in href attribute of A tag using html/template

I create html using html/template However, in the case of the href attribute of the a tag, reserved character escaped by html/template

I know that reserved characters are not escaped by rfc 3986 How to not escape reserved characters in href attribute?

for example…

dict := make(map[string]interface{})
dict["link"] = `https://example.com/()"`
tag := `<a href="{{ $.link }}"></a>`
t, _ := template.New("tag").Parse(tag)

var tpl bytes.Buffer
e := t.Execute(&tpl, dict)
if e != nil {
    fmt.Println(e)
}

fmt.Println(tpl.String())


// <a href="https://example.com/%28%29%22"></a>

my expecting

// <a href="https://example.com/()"></a>

Both URLs are equivalent representations of the same ressource.

both correct?
I think percent encoding is not performed according to the RFC 3986 spec.

Even though you can use a lot of characters directly, the percent encoding can always be used.

Eg. “A” can be written directly, still %41 must be treated equivalently.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.