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

Allow path after a shortcut: go/short/foobar #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion web/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type adminHandler struct {
}

func adminGet(ctx *context.Context, w http.ResponseWriter, r *http.Request) {
p := parseName("/admin/", r.URL.Path)
p, _ := parseName("/admin/", r.URL.Path)

if p == "" {
writeJSONOk(w)
Expand Down
6 changes: 3 additions & 3 deletions web/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ var bannedNames = map[string]bool{

// Parse the shortcut name from the given URL path, given the base URL that is
// handling the request.
func parseName(base, path string) string {
func parseName(base, path string) (string, string) {
t := path[len(base):]
ix := strings.Index(t, "/")
if ix == -1 {
return t
return t, ""
}
return t[:ix]
return t[:ix], t[ix:]
}

// Clean a shortcut name. Currently this just means stripping any leading
Expand Down
6 changes: 3 additions & 3 deletions web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func templateFromAssetFn(fn func() (*asset, error)) (*template.Template, error)
// The default handler responds to most requests. It is responsible for the
// shortcut redirects and for sending unmapped shortcuts to the edit page.
func getDefault(ctx *context.Context, w http.ResponseWriter, r *http.Request) {
p := parseName("/", r.URL.Path)
p, s := parseName("/", r.URL.Path)
if p == "" {
http.Redirect(w, r, "/edit/", http.StatusTemporaryRedirect)
return
Expand All @@ -58,7 +58,7 @@ func getDefault(ctx *context.Context, w http.ResponseWriter, r *http.Request) {
}

http.Redirect(w, r,
rt.URL,
rt.URL+s,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like s contains the leading slash... i don't think it should.
you might want to add after an param= at the end, but now I am getting param=/foobar which is not what I want.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added +1 to parseName function

mathieujobin@e47e38e

http.StatusTemporaryRedirect)

}
Expand Down Expand Up @@ -94,7 +94,7 @@ func ListenAndServe(addr string, admin bool, version string, ctx *context.Contex
getDefault(ctx, w, r)
})
mux.HandleFunc("/edit/", func(w http.ResponseWriter, r *http.Request) {
p := parseName("/edit/", r.URL.Path)
p, _ := parseName("/edit/", r.URL.Path)

// if this is a banned name, just redirect to the local URI. That'll show em.
if isBannedName(p) {
Expand Down