Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3032: Remove query parameters in ADD command when the destinatio… #3053

Merged
merged 3 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions pkg/util/command_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,17 @@ func URLDestinationFilepath(rawurl, dest, cwd string, envs []string) (string, er
}
return dest, nil
}
urlBase := filepath.Base(rawurl)
urlBase, err := ResolveEnvironmentReplacement(urlBase, envs, true)

urlBase, err := ResolveEnvironmentReplacement(rawurl, envs, true)
if err != nil {
return "", err
}

urlBase, err = extractFilename(urlBase)
if err != nil {
return "", err
}

destPath := filepath.Join(dest, urlBase)

if !filepath.IsAbs(dest) {
Expand Down Expand Up @@ -470,3 +476,13 @@ 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, error) {
parsedURL, err := url.Parse(rawURL)
if err != nil {
return "", err
}
filename := filepath.Base(parsedURL.Path)
return filename, nil
}
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
Loading