1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-16 18:01:37 +00:00

Remove RequestURI() hack

I can't remember why this change was done.

Let's use only the standard lib.

But it seems to break URL like this one: https://www.deimeke.net/dirk/blog/index.php?/feeds/index.rss2
This commit is contained in:
Frédéric Guillot 2021-09-11 10:58:48 -07:00 committed by fguillot
parent fcd18f0b9c
commit 612f9cdbc8
3 changed files with 2 additions and 77 deletions

View file

@ -7,7 +7,6 @@ package url // import "miniflux.app/url"
import (
"fmt"
"net/url"
"sort"
"strings"
)
@ -81,51 +80,3 @@ func Domain(websiteURL string) string {
return parsedURL.Host
}
// RequestURI returns the encoded URI to be used in HTTP requests.
func RequestURI(websiteURL string) string {
u, err := url.Parse(websiteURL)
if err != nil {
return websiteURL
}
queryValues := u.Query()
u.RawQuery = "" // Clear RawQuery to make sure it's encoded properly.
u.Fragment = "" // Clear fragment because Web browsers strip #fragment before sending the URL to a web server.
var buf strings.Builder
buf.WriteString(u.String())
if len(queryValues) > 0 {
buf.WriteByte('?')
// Sort keys.
keys := make([]string, 0, len(queryValues))
for k := range queryValues {
keys = append(keys, k)
}
sort.Strings(keys)
i := 0
for _, key := range keys {
keyEscaped := url.QueryEscape(key)
values := queryValues[key]
for _, value := range values {
if i > 0 {
buf.WriteByte('&')
}
buf.WriteString(keyEscaped)
// As opposed to the standard library, we append the = only if the value is not empty.
if value != "" {
buf.WriteByte('=')
buf.WriteString(url.QueryEscape(value))
}
i++
}
}
}
return buf.String()
}