Monorepo for Tangled tangled.org

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

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
··· 17 17 {{ end }} 18 18 19 19 {{ define "mainLayout" }} 20 - <div class="px-1 col-span-full flex flex-col gap-4"> 20 + <div class="px-1 flex-grow col-span-full flex flex-col gap-4"> 21 21 {{ block "contentLayout" . }} 22 22 {{ block "content" . }}{{ end }} 23 23 {{ end }}
+14 -10
appview/repo/compare.go
··· 116 116 } 117 117 118 118 // if user is navigating to one of 119 - // /compare/{base}/{head} 120 119 // /compare/{base}...{head} 121 - base := chi.URLParam(r, "base") 122 - head := chi.URLParam(r, "head") 123 - if base == "" && head == "" { 124 - rest := chi.URLParam(r, "*") // master...feature/xyz 125 - parts := strings.SplitN(rest, "...", 2) 126 - if len(parts) == 2 { 127 - base = parts[0] 128 - head = parts[1] 129 - } 120 + // /compare/{base}/{head} 121 + var base, head string 122 + rest := chi.URLParam(r, "*") 123 + 124 + var parts []string 125 + if strings.Contains(rest, "...") { 126 + parts = strings.SplitN(rest, "...", 2) 127 + } else if strings.Contains(rest, "/") { 128 + parts = strings.SplitN(rest, "/", 2) 129 + } 130 + 131 + if len(parts) == 2 { 132 + base = parts[0] 133 + head = parts[1] 130 134 } 131 135 132 136 base, _ = url.PathUnescape(base)
-1
appview/repo/router.go
··· 61 61 // for example: 62 62 // /compare/master...some/feature 63 63 // /compare/master...example.com:another/feature <- this is a fork 64 - r.Get("/{base}/{head}", rp.Compare) 65 64 r.Get("/*", rp.Compare) 66 65 }) 67 66