mirror of
https://github.com/rclone/rclone.git
synced 2025-04-19 18:31:10 +08:00
Merge 71781e2c3fa70147a7b741263300db58eb06997f into 4d38424e6cbb32d07c74d3b4d760af7afb35742d
This commit is contained in:
commit
7280d2a4dc
@ -360,11 +360,26 @@ var (
|
||||
|
||||
// parseName turns a name as found in the page into a remote path or returns an error
|
||||
func parseName(base *url.URL, name string) (string, error) {
|
||||
|
||||
// make URL absolute
|
||||
u, err := rest.URLJoin(base, name)
|
||||
if err != nil {
|
||||
return "", errURLJoinFailed
|
||||
}
|
||||
|
||||
//Some vendors have the format path/to/?dir=dirname instead of path/to/dirname
|
||||
//This can be corrected here to ignore the extranous "?dir="
|
||||
if(len(u.Query()["dir"]) == 1 && len(u.Query()) == 1 ) {
|
||||
dirName := u.Query()["dir"][0]
|
||||
name = name[:strings.Index(name, "?dir=")]
|
||||
name = name + dirName
|
||||
// make URL absolute
|
||||
u, err = rest.URLJoin(base, name)
|
||||
if err != nil {
|
||||
return "", errURLJoinFailed
|
||||
}
|
||||
}
|
||||
|
||||
// check it doesn't have URL parameters
|
||||
uStr := u.String()
|
||||
if strings.Contains(uStr, "?") {
|
||||
|
@ -330,6 +330,8 @@ func TestParseName(t *testing.T) {
|
||||
{"http://example.com/", "potato", nil, "potato"},
|
||||
{"http://example.com/dir/", "potato", nil, "potato"},
|
||||
{"http://example.com/dir/", "potato?download=true", errFoundQuestionMark, ""},
|
||||
{"http://example.com/dir/", "http://example.com/dir/?dir=sweet+potato", nil, "sweet potato"},
|
||||
{"http://example.com/dir/", "?dir=sweet+potato", nil, "sweet potato"},
|
||||
{"http://example.com/dir/", "../dir/potato", nil, "potato"},
|
||||
{"http://example.com/dir/", "..", errNotUnderRoot, ""},
|
||||
{"http://example.com/dir/", "http://example.com/", errNotUnderRoot, ""},
|
||||
|
Loading…
x
Reference in New Issue
Block a user