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: Improved template check #5944

Closed
gopherbot opened this issue Jul 24, 2013 · 7 comments
Closed

text/template: Improved template check #5944

gopherbot opened this issue Jul 24, 2013 · 7 comments

Comments

@gopherbot
Copy link

by kaixinlaoshu2008:

What steps will reproduce the problem?

template.Must(...) [no error]
template.Execute(...) [error]

And I confirm that the background code is correct

What is the expected output?

show the webpage

What do you see instead?

error

Which compiler are you using (5g, 6g, 8g, gccgo)?

8g

Which operating system are you using?

win7

Which version are you using?  (run 'go version')

go1.1

Please provide any additional information below.

I later found that the reasons:One more  <script> on the web page.
so i sugges improving template check
@rsc
Copy link
Contributor

rsc commented Jul 25, 2013

Comment 1:

This report does not contain enough information to act upon.

Status changed to Invalid.

@gopherbot
Copy link
Author

Comment 2 by kaixinlaoshu2008:

1.load template(*.htm)
fileInfoArr, err := ioutil.ReadDir(TEMPLATE_DIR)
    if err != nil {
        panic(err)
        return
    }
    var templateName, templatePath string
    for _, fileInfo := range fileInfoArr {
        templateName = fileInfo.Name()
        if ext := path.Ext(templateName); ext != ".htm" {
            continue
        }
        templatePath = TEMPLATE_DIR + "/" + templateName
        //log.Println("Loading template:", templatePath)
        t := template.Must(template.ParseFiles(templatePath))
        templates[templateName] = t
    }
//Call the function
func renderHtml(w http.ResponseWriter, tmpl string, locals map[string]interface{}) (err
error) {
    log.Printf("read templates:" + tmpl)
    tmpl += ".htm"
    err = templates[tmpl].Execute(w, locals)
    return
}
2.load auth.htm
    renderHtml(w, "auth", map[string]interface{}{
        "error": err_info,
        "Id": id,
    })
when One more  <script> on auth.htm, template.Execute error and the page cannot
show.

@adg
Copy link
Contributor

adg commented Jul 26, 2013

Comment 3:

What error messages do you get?

Status changed to WaitingForReply.

@rsc
Copy link
Contributor

rsc commented Nov 27, 2013

Comment 4:

Labels changed: added go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 6:

Labels changed: added release-none, removed go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 7:

Labels changed: added repo-main.

@davecheney
Copy link
Contributor

Comment 8:

Status changed to TimedOut.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
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

4 participants