1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-06-25 19:55:22 +00:00

🔥 Use gemini.QueryEscape instead

This commit is contained in:
makeworld 2020-08-27 20:04:02 -04:00
parent dbe87a3e99
commit 11c3b1fec9
3 changed files with 3 additions and 9 deletions

View File

@ -11,6 +11,7 @@ import (
"github.com/makeworld-the-better-one/amfora/config" "github.com/makeworld-the-better-one/amfora/config"
"github.com/makeworld-the-better-one/amfora/renderer" "github.com/makeworld-the-better-one/amfora/renderer"
"github.com/makeworld-the-better-one/amfora/structs" "github.com/makeworld-the-better-one/amfora/structs"
"github.com/makeworld-the-better-one/go-gemini"
"github.com/spf13/viper" "github.com/spf13/viper"
"gitlab.com/tslocum/cview" "gitlab.com/tslocum/cview"
) )
@ -172,7 +173,7 @@ func Init() {
// Detect if it's a search or URL // Detect if it's a search or URL
if strings.Contains(query, " ") || if strings.Contains(query, " ") ||
(!strings.Contains(query, "//") && !strings.Contains(query, ".") && !strings.HasPrefix(query, "about:")) { (!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 cache.RemovePage(u) // Don't use the cached version of the search
URL(u) URL(u)
} else { } else {

View File

@ -419,7 +419,7 @@ func handleURL(t *tab, u string, numRedirects int) (string, bool) {
if ok { if ok {
// Make another request with the query string added // Make another request with the query string added
// + chars are replaced because PathEscape doesn't do that // + chars are replaced because PathEscape doesn't do that
parsed.RawQuery = queryEscape(userInput) parsed.RawQuery = gemini.QueryEscape(userInput)
if len(parsed.String()) > gemini.URLMaxLength { if len(parsed.String()) > gemini.URLMaxLength {
Error("Input Error", "URL for that input would be too long.") Error("Input Error", "URL for that input would be too long.")
return ret("", false) return ret("", false)

View File

@ -3,7 +3,6 @@ package display
import ( import (
"errors" "errors"
"net/url" "net/url"
"strings"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
@ -45,12 +44,6 @@ func textWidth() int {
return viper.GetInt("a-general.max_width") 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. // 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 // It also returns an error if it could not resolve the links, which should be displayed
// to the user. // to the user.