diff --git a/display/display.go b/display/display.go index 76c05ec..2aa331c 100644 --- a/display/display.go +++ b/display/display.go @@ -11,6 +11,7 @@ import ( "github.com/makeworld-the-better-one/amfora/config" "github.com/makeworld-the-better-one/amfora/renderer" "github.com/makeworld-the-better-one/amfora/structs" + "github.com/makeworld-the-better-one/go-gemini" "github.com/spf13/viper" "gitlab.com/tslocum/cview" ) @@ -172,7 +173,7 @@ func Init() { // Detect if it's a search or URL if strings.Contains(query, " ") || (!strings.Contains(query, "//") && !strings.Contains(query, ".") && !strings.HasPrefix(query, "about:")) { - u := viper.GetString("a-general.search") + "?" + queryEscape(query) + u := viper.GetString("a-general.search") + "?" + gemini.QueryEscape(query) cache.RemovePage(u) // Don't use the cached version of the search URL(u) } else { diff --git a/display/private.go b/display/private.go index edc5214..7795c6f 100644 --- a/display/private.go +++ b/display/private.go @@ -419,7 +419,7 @@ func handleURL(t *tab, u string, numRedirects int) (string, bool) { if ok { // Make another request with the query string added // + chars are replaced because PathEscape doesn't do that - parsed.RawQuery = queryEscape(userInput) + parsed.RawQuery = gemini.QueryEscape(userInput) if len(parsed.String()) > gemini.URLMaxLength { Error("Input Error", "URL for that input would be too long.") return ret("", false) diff --git a/display/util.go b/display/util.go index 3a70451..e03fdd6 100644 --- a/display/util.go +++ b/display/util.go @@ -3,7 +3,6 @@ package display import ( "errors" "net/url" - "strings" "github.com/spf13/viper" ) @@ -45,12 +44,6 @@ func textWidth() int { return viper.GetInt("a-general.max_width") } -// queryEscape is the same as url.PathEscape, but it also replaces the +. -// This is because Gemini requires percent-escaping for queries. -func queryEscape(path string) string { - return strings.ReplaceAll(url.PathEscape(path), "+", "%2B") -} - // resolveRelLink returns an absolute link for the given absolute link and relative one. // It also returns an error if it could not resolve the links, which should be displayed // to the user.