aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFeuerfuchs <git@feuerfuchs.dev>2019-11-11 22:04:20 +0100
committerFeuerfuchs <git@feuerfuchs.dev>2019-11-11 22:04:20 +0100
commitcd8943a3f9e0cbdfe02bdfcdc0393946c9265731 (patch)
tree4c10ed5ce71d3ff9d13f626877507bde904e7098
parentPrefix instead of equality to determine page type (diff)
downloadgopherproxy-cd8943a3f9e0cbdfe02bdfcdc0393946c9265731.tar.gz
gopherproxy-cd8943a3f9e0cbdfe02bdfcdc0393946c9265731.tar.bz2
gopherproxy-cd8943a3f9e0cbdfe02bdfcdc0393946c9265731.zip
Fix: Correctly handle URIs where the type is not separated by a slash
-rw-r--r--gopherproxy.go13
-rw-r--r--template.go5
2 files changed, 17 insertions, 1 deletions
diff --git a/gopherproxy.go b/gopherproxy.go
index 8b33c05..d98ef7c 100644
--- a/gopherproxy.go
+++ b/gopherproxy.go
@@ -132,7 +132,7 @@ func GopherHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass
132 RawText string 132 RawText string
133 Lines []Item 133 Lines []Item
134 Error bool 134 Error bool
135 }{uri, fmt.Sprintf("%s/%s", hostport, uri), assetList, fmt.Sprintf("Error: %s", err), nil, true}) 135 }{"", hostport, assetList, fmt.Sprintf("Error: %s", err), nil, true})
136 return 136 return
137 } 137 }
138 138
@@ -346,6 +346,17 @@ func ListenAndServe(bind, robotsfile string, robotsdebug bool, vipsconcurrency i
346 var inputStr = fmt.Sprintf("%v", input) 346 var inputStr = fmt.Sprintf("%v", input)
347 return re.ReplaceAllString(inputStr, output) 347 return re.ReplaceAllString(inputStr, output)
348 }, 348 },
349 "trimLeftChar": func(s string) string {
350 for i := range s {
351 if i > 0 {
352 return s[i:]
353 }
354 }
355 return s[:0]
356 },
357 "hasPrefix": func(s string, prefix string) bool {
358 return strings.HasPrefix(s, prefix)
359 },
349 } 360 }
350 361
351 tpl, err = template.New("gophermenu").Funcs(funcMap).Parse(tpltext) 362 tpl, err = template.New("gophermenu").Funcs(funcMap).Parse(tpltext)
diff --git a/template.go b/template.go
index f58349e..7aee61a 100644
--- a/template.go
+++ b/template.go
@@ -43,6 +43,11 @@ var tpltext = `<!doctype html>
43 <a href="{{ $href }}" class="location__uripart">{{ . }}</a> 43 <a href="{{ $href }}" class="location__uripart">{{ . }}</a>
44 {{- else -}} 44 {{- else -}}
45 {{- $href = printf "%s/1" $href -}} 45 {{- $href = printf "%s/1" $href -}}
46 {{- $part = $part | trimLeftChar -}}
47 {{- if not (eq $part "") -}}
48 {{- $href = printf "%s/%s" $href $part -}}
49 <span class="location__slash">/</span><a href="{{ $href }}" class="location__uripart">{{ $part }}</a>
50 {{- end -}}
46 {{- end -}} 51 {{- end -}}
47 {{- end -}} 52 {{- end -}}
48 {{- if ne (len $uriParts) 0 -}} 53 {{- if ne (len $uriParts) 0 -}}