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: Calling Template.Execute with no top-level template panics #10786

Closed
anacrolix opened this issue May 12, 2015 · 6 comments
Closed

Comments

@anacrolix
Copy link
Contributor

t := template.Must(template.New("").Funcs(irrelevantFuncs).ParseFiles("base.html", "notbase.html"))
t.Execute(w, data)

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x20 pc=0x418b6b4]

goroutine 1 [running]:
html/template.(*Template).escape(0xc208091f20, 0x0, 0x0)
    /Users/anacrolix/src/go/src/html/template/template.go:59 +0xe4
html/template.(*Template).Execute(0xc208091f20, 0x49a1ec8, 0xc208048010, 0x0, 0x0, 0x0, 0x0)
    /Users/anacrolix/src/go/src/html/template/template.go:75 +0x3d

Compare calling t.ExecuteTemplate(w, "", data) which gives error html/template: "" is an incomplete template. There should be a suitable error for Template.Execute, or the docs improved.

@robpike robpike self-assigned this May 12, 2015
@robpike
Copy link
Contributor

robpike commented May 12, 2015

Please provide a complete example, avoiding files if possible.

@anacrolix anacrolix changed the title text/template: Calling Template.Execute with no top-level template panics html/template: Calling Template.Execute with no top-level template panics May 13, 2015
@anacrolix
Copy link
Contributor Author

Thanks, I've boiled it down to this: http://play.golang.org/p/EQyvlM7LYX

It doesn't occur with text/template, but does with html/template.

@syst3mw0rm
Copy link
Contributor

@anacrolix what go version are you using? I'm not facing any issue on tip.

@anacrolix
Copy link
Contributor Author

I was running go1.4. It does not happen in master. go version devel +7eec656 Wed May 20 07:54:37 2015 +0000 darwin/amd64

I have a feeling I already reported this issue once before.

@robpike
Copy link
Contributor

robpike commented May 20, 2015

Fixed at tip.

@robpike robpike closed this as completed May 20, 2015
@avdept
Copy link

avdept commented Jun 14, 2015

@robpike Where can i see changes?

@golang golang locked and limited conversation to collaborators Jun 25, 2016
@rsc rsc unassigned robpike Jun 23, 2022
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

5 participants