make gemini url safe
alex wennerberg alex@alexwennerberg.com
Tue, 26 Jan 2021 20:54:14 -0800
2 files changed,
8 insertions(+),
2 deletions(-)
M
http.go
→
http.go
@@ -772,7 +772,13 @@ }
func runHTTPServer() { log.Printf("Running http server with hostname %s on port %d.", c.Host, c.HttpPort) var err error - t = template.New("main").Funcs(template.FuncMap{"parent": path.Dir, "hasSuffix": strings.HasSuffix}) + t = template.New("main").Funcs(template.FuncMap{"parent": path.Dir, "hasSuffix": strings.HasSuffix, + "safeGeminiURL": func(u string) template.URL { + if strings.HasPrefix(u, "gemini://") { + return template.URL(u) + } + return "" + }}) t, err = t.ParseGlob(path.Join(c.TemplatesDirectory, "*.html")) if err != nil { log.Fatal(err)
M
templates/user_page.html
→
templates/user_page.html
@@ -22,7 +22,7 @@ <br>
<br> {{ end }} <div class="footer"> - Proxied from the original at <a href="{{.URI.String}}">{{.URI.String}}</a> (<a href="https://admin.flounder.online/gemini.gmi">about Gemini</a>) <a href="?raw=1">raw</a></div> + Proxied from the original at <a href="{{safeGeminiURL .URI.String}}">{{.URI.String}}</a> (<a href="https://admin.flounder.online/gemini.gmi">about Gemini</a>) <a href="?raw=1">raw</a></div> </main> </body> </html>