Skip to content

Commit

Permalink
gopages: Encode page URLs instead of failable decoding (JohnStarich#8)
Browse files Browse the repository at this point in the history
Fix an issue where paths that couldn't be URL decoded were failing to parse and panicking.

We don't even need to parse URLs in this scenario, so remove the error path entirely.

Fix JohnStarich#7
  • Loading branch information
JohnStarich authored Aug 29, 2021
1 parent e473a66 commit 614c33c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 1 addition & 4 deletions gopages/internal/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,7 @@ func doRequest(do func(w http.ResponseWriter)) ([]byte, error) {
}

func getPage(pres *godoc.Presentation, path string) ([]byte, error) {
u, err := url.Parse(path)
if err != nil {
panic(err)
}
u := &url.URL{Path: path}
return doRequest(func(w http.ResponseWriter) {
pres.ServeHTTP(w, &http.Request{URL: u})
})
Expand Down
4 changes: 4 additions & 0 deletions gopages/internal/generate/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ package mylib
`)
writeFile(".git/something", `ignored dot dir`)
writeFile(".dotfile", `ignored dot file`)
writeFile("%name.PascalCased%/other.go", `package bad_url_decode`)

args := flags.Args{}
const modulePackage = "github.com/my/thing"
Expand All @@ -71,13 +72,16 @@ package mylib
"index.html",
"pkg/github.com/index.html",
"pkg/github.com/my/index.html",
"pkg/github.com/my/thing/%name.PascalCased%/index.html", // Verifies fix for https://github.com/JohnStarich/go/issues/7
"pkg/github.com/my/thing/index.html",
"pkg/github.com/my/thing/internal/hello/index.html",
"pkg/github.com/my/thing/internal/index.html",
"pkg/github.com/my/thing/mylib/index.html",
"pkg/index.html",
"src/github.com/index.html",
"src/github.com/my/index.html",
"src/github.com/my/thing/%name.PascalCased%/index.html",
"src/github.com/my/thing/%name.PascalCased%/other.go.html",
"src/github.com/my/thing/index.html",
"src/github.com/my/thing/internal/hello/hello.go.html",
"src/github.com/my/thing/internal/hello/index.html",
Expand Down

0 comments on commit 614c33c

Please sign in to comment.