Merge pull request #18736 from Luap99/completion-panic

completion: fix panic in simplePathJoinUnix()
This commit is contained in:
OpenShift Merge Robot
2023-05-30 12:11:59 -04:00
committed by GitHub
2 changed files with 10 additions and 0 deletions

View File

@ -362,6 +362,11 @@ func getPathCompletion(root string, toComplete string) ([]string, cobra.ShellCom
// We cannot use path.Join() for the completions logic because this one always calls Clean() on
// the path which changes it from the input.
func simplePathJoinUnix(p1, p2 string) string {
if len(p1) == 0 {
// Special case if p1 is not set just return p2 as is
// and do not add a slash as the input didn't contain one either.
return p2
}
if p1[len(p1)-1] == '/' {
return p1 + p2
}

View File

@ -353,6 +353,11 @@ function _check_no_suggestions() {
run_completion $cmd $IMAGE "/etc/os-"
assert "$output" =~ ".*^/etc/os-release\$.*" "/etc files suggested (cmd: podman $cmd /etc/os-)"
# regression check for https://bugzilla.redhat.com/show_bug.cgi?id=2209809
# check for relative directory without slash in path.
run_completion $cmd $IMAGE "e"
assert "$output" =~ ".*^etc/\$.*" "etc dir suggested (cmd: podman $cmd e)"
# check completion with relative path components
# It is important the we will still use the image root and not escape to the host
run_completion $cmd $IMAGE "../../"