Merge 71781e2c3fa70147a7b741263300db58eb06997f into 4d38424e6cbb32d07c74d3b4d760af7afb35742d

This commit is contained in:
Anirudh "Luca" Katoch 2025-03-20 09:59:56 +00:00 committed by GitHub
commit 7280d2a4dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View File

@ -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, "?") {

View File

@ -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, ""},