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: Template redefinition doesn't work when new template content is empty or whitespace-only. #16913

Closed
dmitshur opened this issue Aug 29, 2016 · 1 comment
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dmitshur
Copy link
Contributor

dmitshur commented Aug 29, 2016

This is potentially related to #16912. I couldn't really find explicit documentation on template redefinition, and any limitations/restrictions on it.

From looking around the CL that implemented it and its commit message, it made it sound like it should be possible to simply redefine any template by defining it again, and then have it take on the new template content.

In other words, I expected a template redefined to new content X to behave as if it were a template first created with content X. This turned out not to be the case for some content X (so far, it happens when content is empty or contains whitespace and template comments only).

  1. What version of Go are you using (go version)?

    go version devel +2f679d7 Sun Aug 28 21:38:09 2016 +0000 linux/amd64
    

    (That's the latest tip commit 2f679d7 from a day ago as of posting this.)

    I initially ran into this issue on Go 1.7, but I tried it on latest tip in order to check if it has since been fixed or not. It's not.

  2. What operating system and processor architecture are you using (go env)?

    $ go env
    GOARCH="amd64"
    GOBIN=""
    GOEXE=""
    GOHOSTARCH="amd64"
    GOHOSTOS="linux"
    GOOS="linux"
    GOPATH="/home/ubuntu/GoPath"
    GORACE=""
    GOROOT="/home/ubuntu/go"
    GOTOOLDIR="/home/ubuntu/go/pkg/tool/linux_amd64"
    CC="gcc"
    GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build390318819=/tmp/go-build -gno-record-gcc-switches"
    CXX="g++"
    CGO_ENABLED="1"
    
  3. What did you do?
    If possible, provide a recipe for reproducing the error.
    A complete runnable program is good.
    A link on play.golang.org is best.

    I redefined a template with an empty template, or a template consisting of whitespace (and template comments).

    https://play.golang.org/p/c3K-zyJ4dd

  4. What did you expect to see?

    Names:
    - Gamora
    - Groot
    - Nebula
    - Rocket
    - Star-Lord
    Names:Names:
    
  5. What did you see instead?

    The template redefinition was effectively ignored. No error, and the old template contents were still used.

    Names:
    - Gamora
    - Groot
    - Nebula
    - Rocket
    - Star-Lord
    Names:
    - Gamora
    - Groot
    - Nebula
    - Rocket
    - Star-Lord
    Names:
    - Gamora
    - Groot
    - Nebula
    - Rocket
    - Star-Lord
    

    If you include any non-whitespace character in the redefined template content, such as x, then it works as expected, e.g.:

    Names:
    - Gamora
    - Groot
    - Nebula
    - Rocket
    - Star-Lord
    Names:xNames:x
    
@quentinmit quentinmit added this to the Go1.8 milestone Sep 6, 2016
@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 10, 2016
@gopherbot
Copy link

CL https://golang.org/cl/31459 mentions this issue.

@golang golang locked and limited conversation to collaborators Oct 19, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants