mirror of
https://github.com/miniflux/v2.git
synced 2024-09-28 13:21:52 +02: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:
parent
fcd18f0b9c
commit
612f9cdbc8
@ -21,7 +21,6 @@ import (
|
|||||||
"miniflux.app/errors"
|
"miniflux.app/errors"
|
||||||
"miniflux.app/logger"
|
"miniflux.app/logger"
|
||||||
"miniflux.app/timer"
|
"miniflux.app/timer"
|
||||||
url_helper "miniflux.app/url"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -40,7 +39,6 @@ var (
|
|||||||
type Client struct {
|
type Client struct {
|
||||||
inputURL string
|
inputURL string
|
||||||
|
|
||||||
requestURL string
|
|
||||||
requestEtagHeader string
|
requestEtagHeader string
|
||||||
requestLastModifiedHeader string
|
requestLastModifiedHeader string
|
||||||
requestAuthorizationHeader string
|
requestAuthorizationHeader string
|
||||||
@ -90,9 +88,8 @@ func (c *Client) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
`InputURL=%q RequestURL=%q ETag=%s LastMod=%s Auth=%v UserAgent=%q Verify=%v`,
|
`InputURL=%q ETag=%s LastMod=%s Auth=%v UserAgent=%q Verify=%v`,
|
||||||
c.inputURL,
|
c.inputURL,
|
||||||
c.requestURL,
|
|
||||||
etagHeader,
|
etagHeader,
|
||||||
lastModifiedHeader,
|
lastModifiedHeader,
|
||||||
c.requestAuthorizationHeader != "" || (c.requestUsername != "" && c.requestPassword != ""),
|
c.requestAuthorizationHeader != "" || (c.requestUsername != "" && c.requestPassword != ""),
|
||||||
@ -263,8 +260,7 @@ func (c *Client) executeRequest(request *http.Request) (*Response, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) buildRequest(method string, body io.Reader) (*http.Request, error) {
|
func (c *Client) buildRequest(method string, body io.Reader) (*http.Request, error) {
|
||||||
c.requestURL = url_helper.RequestURI(c.inputURL)
|
request, err := http.NewRequest(method, c.inputURL, body)
|
||||||
request, err := http.NewRequest(method, c.requestURL, body)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
49
url/url.go
49
url/url.go
@ -7,7 +7,6 @@ package url // import "miniflux.app/url"
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"sort"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -81,51 +80,3 @@ func Domain(websiteURL string) string {
|
|||||||
|
|
||||||
return parsedURL.Host
|
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()
|
|
||||||
}
|
|
||||||
|
@ -88,25 +88,3 @@ func TestDomain(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRequestURI(t *testing.T) {
|
|
||||||
scenarios := map[string]string{
|
|
||||||
"https://www.example.org": "https://www.example.org",
|
|
||||||
"https://user:password@www.example.org": "https://user:password@www.example.org",
|
|
||||||
"https://www.example.org/path with spaces": "https://www.example.org/path%20with%20spaces",
|
|
||||||
"https://www.example.org/path#test": "https://www.example.org/path",
|
|
||||||
"https://www.example.org/path?abc#test": "https://www.example.org/path?abc",
|
|
||||||
"https://www.example.org/path?a=b&a=c": "https://www.example.org/path?a=b&a=c",
|
|
||||||
"https://www.example.org/path?a=b&a=c&d": "https://www.example.org/path?a=b&a=c&d",
|
|
||||||
"https://www.example.org/path?atom": "https://www.example.org/path?atom",
|
|
||||||
"https://www.example.org/path?测试=测试": "https://www.example.org/path?%E6%B5%8B%E8%AF%95=%E6%B5%8B%E8%AF%95",
|
|
||||||
"https://www.example.org/url=http%3A%2F%2Fwww.example.com%2Ffeed%2F&max=20": "https://www.example.org/url=http%3A%2F%2Fwww.example.com%2Ffeed%2F&max=20",
|
|
||||||
}
|
|
||||||
|
|
||||||
for input, expected := range scenarios {
|
|
||||||
actual := RequestURI(input)
|
|
||||||
if actual != expected {
|
|
||||||
t.Errorf(`Unexpected result, got %q instead of %q`, actual, expected)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user