-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: ambiguous errors when style tag is not closed #29269
Comments
I looked into this and it is more than just ambiguous errors. It seems to be a bug that confuses the escaper into thinking that it is inside a tag and not in CSS state. (I don't think it is related to the style tag being closed or not) This code: t := template.Must(template.New("base").Parse(`<style>
{{/*This is fine*/}}
<a href="{{.}}"></a>
{{if true}}
{{/*The colon is important*/}}
<a href=":{{.}}"></a>
{{if true}}
{{/*This is fine*/}}
<a href="{{.}}"></a>
{{end}}
{{end}}
{{if true}}
{{/*This is not fine*/}}
<a href="a?{{.}}"></a>
{{end}}
</style>`))
err := t.Execute(os.Stdout, "{") Produces:
I'll look into this and try to find the root cause. @mikesamuel how should we escape HTML stuff inside a |
@empijei As you say,
I'm unsure why The "extra trailing space" is necessary for CSS escaping when you don't know the next character.
Agreed.
but that would require an extra context bit for foreign content mode for no apparent benefit. Biasing towards the second would break <style>
/* Make <b> blue */ b { color: blue }
/* Make <p> pink */ p { color: pink }
</style> |
Thanks @mikesamuel for the response. I dug a little bit more into this. About the errorThe state of the parser when the reported error is returned is:
This is why the error is Some additional doubtsThe parser gets in the t := template.Must(template.New("a").Parse(`
<style>{{if true}} "a{{.}}" {{end}} "{{.}}"`))
fmt.Printf("%v",t.Execute(os.Stdout, "")) This gives the error above because the The code below, instead, returns an error stating that template "ends in a non-text context" and both branches of the join are in t := template.Must(template.New("a").Parse(`
<style>{{if true}} "{{.}}" {{end}} "{{.}}"`))
// ↑ Removed `a`
fmt.Printf("%v", t.Execute(os.Stdout, "")) This is due to the fact that in the initial part of a URL we stay in Why do closing quotes behave differently in these cases? |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Ran the following program: https://play.golang.org/p/BtMWAAxnb3o
What did you expect to see?
Program not returning an error, or at least an error informing that the style tag was not closed.
What did you see instead?
The text was updated successfully, but these errors were encountered: