mirror of https://github.com/rclone/rclone.git
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
|
// 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) {
|
func parseName(base *url.URL, name string) (string, error) {
|
||||||
|
|
||||||
// make URL absolute
|
// make URL absolute
|
||||||
u, err := rest.URLJoin(base, name)
|
u, err := rest.URLJoin(base, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errURLJoinFailed
|
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
|
// check it doesn't have URL parameters
|
||||||
uStr := u.String()
|
uStr := u.String()
|
||||||
if strings.Index(uStr, "?") >= 0 {
|
if strings.Index(uStr, "?") >= 0 {
|
||||||
|
|
|
@ -251,6 +251,8 @@ func TestParseName(t *testing.T) {
|
||||||
{"http://example.com/", "potato", nil, "potato"},
|
{"http://example.com/", "potato", nil, "potato"},
|
||||||
{"http://example.com/dir/", "potato", nil, "potato"},
|
{"http://example.com/dir/", "potato", nil, "potato"},
|
||||||
{"http://example.com/dir/", "potato?download=true", errFoundQuestionMark, ""},
|
{"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/", "../dir/potato", nil, "potato"},
|
||||||
{"http://example.com/dir/", "..", errNotUnderRoot, ""},
|
{"http://example.com/dir/", "..", errNotUnderRoot, ""},
|
||||||
{"http://example.com/dir/", "http://example.com/", errNotUnderRoot, ""},
|
{"http://example.com/dir/", "http://example.com/", errNotUnderRoot, ""},
|
||||||
|
|
Loading…
Reference in New Issue