From 9f2e515a5ef6b27ee393a67b5d904e6e1ffd3242 Mon Sep 17 00:00:00 2001 From: James Mills Date: Tue, 13 Jun 2017 01:29:12 -0700 Subject: Fix handling of queries / indexsearch (itemtype 7) --- gopherproxy.go | 16 +++++++++++++--- template.go | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/gopherproxy.go b/gopherproxy.go index 4a2255f..8c85448 100644 --- a/gopherproxy.go +++ b/gopherproxy.go @@ -45,7 +45,7 @@ func renderDirectory(w http.ResponseWriter, tpl *template.Template, hostport str } else { hostport = fmt.Sprintf("%s:%d", x.Host, x.Port) } - path := url.QueryEscape(x.Selector) + path := url.PathEscape(x.Selector) path = strings.Replace(path, "%2F", "/", -1) tr.Link = template.URL( fmt.Sprintf( @@ -73,25 +73,35 @@ func MakeGopherProxyHandler(tpl *template.Template, uri string) Handler { return func(w http.ResponseWriter, req *http.Request) { parts := strings.Split(strings.TrimPrefix(req.URL.Path, "/"), "/") hostport := parts[0] - path := strings.Join(parts[1:], "/") if len(hostport) == 0 { http.Redirect(w, req, "/"+uri, http.StatusFound) return } + var qs string + + path := strings.Join(parts[1:], "/") + + if req.URL.RawQuery != "" { + qs = fmt.Sprintf("?%s", url.QueryEscape(req.URL.RawQuery)) + } + uri, err := url.QueryUnescape(path) if err != nil { io.WriteString(w, fmt.Sprintf("Error:
%s
", err)) return } + res, err := gopher.Get( fmt.Sprintf( - "gopher://%s/%s", + "gopher://%s/%s%s", hostport, uri, + qs, ), ) + if err != nil { io.WriteString(w, fmt.Sprintf("Error:
%s
", err)) return diff --git a/template.go b/template.go index 604f380..6fb1162 100644 --- a/template.go +++ b/template.go @@ -22,7 +22,7 @@ $(document).ready(function () { e.preventDefault(); var query = prompt("Please enter required input: ", ""); if (query != null) { - window.location = e.target.href + "%09" + query; + window.location = e.target.href + "?" + query; } }); }); -- cgit v1.2.3-70-g09d2