appview/repo: allow compare URLs to not be path escaped #828

merged
opened by oppi.li targeting master from op/zwwnppvnssrx

this changes the routing logic slightly to allow non-path escaped refs in compare urls that use the ... syntax:

previously only this worked:

/compare/master/sl%2Fuvpzuszrulvq
/compare/master...sl%2Fuvpzuszrulvq

with this patch:

/compare/master/sl%2Fuvpzuszrulvq
/compare/master...sl%2Fuvpzuszrulvq
/compare/master...sl/uvpzuszrulvq (new)

Signed-off-by: oppiliappan me@oppi.li

Changed files
+15 -12
appview
pages
templates
repo
compare
repo
+1 -1
appview/pages/templates/repo/compare/compare.html
···
{{ end }}
{{ define "mainLayout" }}
-
<div class="px-1 col-span-full flex flex-col gap-4">
+
<div class="px-1 flex-grow col-span-full flex flex-col gap-4">
{{ block "contentLayout" . }}
{{ block "content" . }}{{ end }}
{{ end }}
+14 -10
appview/repo/compare.go
···
}
// if user is navigating to one of
-
// /compare/{base}/{head}
// /compare/{base}...{head}
-
base := chi.URLParam(r, "base")
-
head := chi.URLParam(r, "head")
-
if base == "" && head == "" {
-
rest := chi.URLParam(r, "*") // master...feature/xyz
-
parts := strings.SplitN(rest, "...", 2)
-
if len(parts) == 2 {
-
base = parts[0]
-
head = parts[1]
-
}
+
// /compare/{base}/{head}
+
var base, head string
+
rest := chi.URLParam(r, "*")
+
+
var parts []string
+
if strings.Contains(rest, "...") {
+
parts = strings.SplitN(rest, "...", 2)
+
} else if strings.Contains(rest, "/") {
+
parts = strings.SplitN(rest, "/", 2)
+
}
+
+
if len(parts) == 2 {
+
base = parts[0]
+
head = parts[1]
}
base, _ = url.PathUnescape(base)
-1
appview/repo/router.go
···
// for example:
// /compare/master...some/feature
// /compare/master...example.com:another/feature <- this is a fork
-
r.Get("/{base}/{head}", rp.Compare)
r.Get("/*", rp.Compare)
})