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

text/template: AddParseTree can't replace empty templates, whereas Parse can #10990

Closed
chowey opened this issue May 29, 2015 · 2 comments
Closed

text/template: AddParseTree can't replace empty templates, whereas Parse can #10990

chowey opened this issue May 29, 2015 · 2 comments
Milestone

Comments

@chowey
Copy link

@chowey chowey commented May 29, 2015

Given that I have an empty "test" template:

tpl, err := template.New("main").Parse(`
    {{template "test" .}}
    {{define "test"}}{{end}}
`)

this works:

tpl, err = tpl.New("test").Parse(`This is a test`)
// no error

and this fails:

test, err := template.New("test").Parse(`This is a test`)
tpl, err = tpl.AddParseTree("test", test.Tree)
// error

I think the AddParseTree conditional should be changed to:

    if t.common != nil
        if old := t.tmpl[name]; old != nil && !parse.IsEmptyTree(old.Root) {
            return nil, fmt.Errorf("template: redefinition of template %q", name)
        }
    }

This would make the behavior of AddParseTree consistent with Parse.

@chowey chowey changed the title text/template: AddParseTree can't replace empty trees, whereas Parse can text/template: AddParseTree can't replace empty templates, whereas Parse can May 29, 2015
@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Jun 3, 2015
@chowey
Copy link
Author

@chowey chowey commented Jul 10, 2015

Is this now fixed with 6d9df14?

@chowey
Copy link
Author

@chowey chowey commented Aug 6, 2015

Just tested - yes this is fixed now.

@chowey chowey closed this Aug 6, 2015
@golang golang locked and limited conversation to collaborators Aug 5, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.