mirror of
https://github.com/rclone/rclone
synced 2024-11-21 22:50:16 +01:00
http: Support for directory-lister for the http remote
This commit is contained in:
parent
41f561bf26
commit
71781e2c3f
@ -296,11 +296,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.Index(uStr, "?") >= 0 {
|
||||
|
@ -251,6 +251,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…
Reference in New Issue
Block a user