Skip to content

Commit

Permalink
add error in extractFilename and realize that ResolveEnvironmentRepla…
Browse files Browse the repository at this point in the history
…cement better execute before getting the filename
  • Loading branch information
prima101112 committed Mar 21, 2024
1 parent 1705f17 commit 49a6787
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 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 := extractFilename(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 @@ -472,9 +478,11 @@ func getUID(userStr string) (uint32, error) {
}

// ExtractFilename extracts the filename from a URL without its query url
func extractFilename(rawURL string) string {
// not necessarily return an error, due to parsing ambiguities https://pkg.go.dev/net/url#Parse
parsedURL, _ := url.Parse(rawURL)
func extractFilename(rawURL string) (string, error) {
parsedURL, err := url.Parse(rawURL)
if err != nil {
return "", err
}
filename := filepath.Base(parsedURL.Path)
return filename
return filename, nil
}

0 comments on commit 49a6787

Please sign in to comment.