Closed jakdept closed 9 years ago
I confirmed this is begin kicked by line 52 of handlers.go
:
func MarkdownHandler(responsePipe http.ResponseWriter, request *http.Request, serverConfig ServerSection) {
var err error
requestPath := strings.TrimPrefix(request.URL.Path, serverConfig.Prefix)
// If the request is empty, set it to the default.
if request.URL.Path == "" || request.URL.Path == "/" {
request.URL.Path = serverConfig.Default
}
// If the request doesn't end in .md, add that
if !strings.HasSuffix(requestPath, ".md") {
requestPath = requestPath + ".md"
}
pdata := new(PageMetadata)
err = pdata.LoadPage(serverConfig.Path + requestPath)
if err != nil {
log.Printf("request [ %s ] points to an bad file target [ %s ] sent to server %s", request.URL.Path, requestPath, serverConfig.Prefix)
http.Error(responsePipe, err.Error(), http.StatusNotFound)
return
}
if pdata.MatchedTag(serverConfig.Restricted) {
log.Printf("request [ %s ] was against a page [ %s ] with a restricted tag", request.URL.Path, requestPath)
http.Error(responsePipe, err.Error(), http.StatusNotFound)
//http.Error(responsePipe, err.Error(), http.StatusForbidden)
return
}
// parse any markdown in the input
body := template.HTML(bodyParseMarkdown(pdata.Page))
toc := template.HTML(tocParseMarkdown(pdata.Page))
keywords := pdata.PrintKeywords()
topics := pdata.PrintTopics(serverConfig.TopicURL)
// ##TODO## put this template right in the function call
// Then remove the Page Struct above
response := Page{Title: "", ToC: toc, Body: body, Keywords: keywords, Topics: topics}
err = allTemplates.ExecuteTemplate(responsePipe, serverConfig.Template, response)
if err != nil {
http.Error(responsePipe, err.Error(), 500)
}
}
The specific line ikicking the error is:
http.Error(responsePipe, err.Error(), http.StatusNotFound)
The third argument to this function call can be replaced without causing the error. You can request a page that is not present without issue (above). You can comment out this line, and it works fine. I copied the line from the 404 check, and compiled with that - and it's the same error.
Turns out that err
is nil when you get a page that exists, but has tags. Thus, you cannot call err.Error()
. Herpity derpity.
Fixed.
When loading a restricted page in the markdown handler, I'm getting a stack dump that looks like:
looking into it.