Skip to content

html/template: srcset incorrectly escaped #17441

@okdave

Description

@okdave

tl;dr: https://play.golang.org/p/8A4TQ1-Kvt

The html/template defaults to the contentTypeURL content type for any attribute that contains the substring "src".

However the srcset attribute is a set of URLs which are separated by whitespace and optional extra size/density indicators (see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-srcset).

For example "image1.jpg w200, image2.jpg w400".

When this is escaped as the contentTypeURL the spaces are encoded, the whole thing looks like a single URL, and the resource fails to load.

tmpl := template.Must(template.New("foo").Parse(`<img srcset="{{.}}">`))
tmpl.Execute(os.Stdout, "1.jpg w200, 2.jpg w200")

Got <img srcset="1.jpg%20w200,%202.jpg%20w200">
Want <img srcset="1.jpg w200, 2.jpg w200">

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions