Fix escaping of queries
This commit is contained in:
parent
24e488a4cb
commit
16739d20d0
@ -155,7 +155,7 @@ func (c *Client) do(req *Request, via []*Request) (*Response, error) {
|
|||||||
input, ok := c.GetInput(resp.Meta, resp.Status == StatusSensitiveInput)
|
input, ok := c.GetInput(resp.Meta, resp.Status == StatusSensitiveInput)
|
||||||
if ok {
|
if ok {
|
||||||
req.URL.ForceQuery = true
|
req.URL.ForceQuery = true
|
||||||
req.URL.RawQuery = url.QueryEscape(input)
|
req.URL.RawQuery = QueryEscape(input)
|
||||||
return c.do(req, via)
|
return c.do(req, via)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
query.go
Normal file
17
query.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package gemini
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// QueryEscape properly escapes a string for use in a Gemini URL query.
|
||||||
|
// It is like url.PathEscape except that it also replaces plus signs with their percent-encoded counterpart.
|
||||||
|
func QueryEscape(query string) string {
|
||||||
|
return strings.ReplaceAll(url.PathEscape(query), "+", "%2B")
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryUnescape is identical to url.PathUnescape.
|
||||||
|
func QueryUnescape(query string) (string, error) {
|
||||||
|
return url.PathUnescape(query)
|
||||||
|
}
|
@ -51,6 +51,9 @@ func NewRequest(rawurl string) (*Request, error) {
|
|||||||
|
|
||||||
// NewRequestFromURL returns a new request for the given URL.
|
// NewRequestFromURL returns a new request for the given URL.
|
||||||
// The host is inferred from the URL.
|
// The host is inferred from the URL.
|
||||||
|
//
|
||||||
|
// Callers should be careful that the URL query is properly escaped.
|
||||||
|
// See the documentation for QueryEscape for more information.
|
||||||
func NewRequestFromURL(url *url.URL) *Request {
|
func NewRequestFromURL(url *url.URL) *Request {
|
||||||
host := url.Host
|
host := url.Host
|
||||||
if url.Port() == "" {
|
if url.Port() == "" {
|
||||||
|
Loading…
Reference in New Issue
Block a user