Skip to content

Commit

Permalink
Fix #3032: Remove query parameters in ADD command when the destinatio…
Browse files Browse the repository at this point in the history
…n is a directory
  • Loading branch information
prima101112 committed Mar 17, 2024
1 parent 8a8323a commit 927eae8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/util/command_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func URLDestinationFilepath(rawurl, dest, cwd string, envs []string) (string, er
}
return dest, nil
}
urlBase := filepath.Base(rawurl)
urlBase := extractFilename(rawurl)
urlBase, err := ResolveEnvironmentReplacement(urlBase, envs, true)
if err != nil {
return "", err
Expand Down Expand Up @@ -469,3 +469,11 @@ func getUID(userStr string) (uint32, error) {
}
return uint32(uid), nil
}

// ExtractFilename extracts the filename from a URL without its query url
func extractFilename(rawUrl string) string {

Check failure on line 474 in pkg/util/command_util.go

View workflow job for this annotation

GitHub Actions / tests

func parameter `rawUrl` should be `rawURL` (golint)
// not necessarily return an error, due to parsing ambiguities https://pkg.go.dev/net/url#Parse
parsedUrl, _ := url.Parse(rawUrl)

Check failure on line 476 in pkg/util/command_util.go

View workflow job for this annotation

GitHub Actions / tests

var `parsedUrl` should be `parsedURL` (golint)
filename := filepath.Base(parsedUrl.Path)
return filename
}
6 changes: 6 additions & 0 deletions pkg/util/command_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ var urlDestFilepathTests = []struct {
dest: "/test",
expectedDest: "/test",
},
{
url: "https://something/something.tar?foo=bar",
cwd: "/cwd",
dest: "/dir/",
expectedDest: "/dir/something.tar",
},
{
url: "https://something/something",
cwd: "/test",
Expand Down

0 comments on commit 927eae8

Please sign in to comment.