diff --git a/cmd/podman/common/completion.go b/cmd/podman/common/completion.go index f78ccf158a..ac487708bc 100644 --- a/cmd/podman/common/completion.go +++ b/cmd/podman/common/completion.go @@ -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 } diff --git a/test/system/600-completion.bats b/test/system/600-completion.bats index cb4a2c5f81..cf0380485c 100644 --- a/test/system/600-completion.bats +++ b/test/system/600-completion.bats @@ -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 "../../"