From ed1083ec27a16f0dae90394c19019183cde74eac Mon Sep 17 00:00:00 2001 From: native-api Date: Thu, 10 Nov 2022 04:46:14 +0300 Subject: [PATCH] Fix resolution of a name that's a prefix of another name (#2521) --- libexec/pyenv-latest | 6 ++++++ test/latest.bats | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/libexec/pyenv-latest b/libexec/pyenv-latest index 2b265a68..8bc1b3f5 100755 --- a/libexec/pyenv-latest +++ b/libexec/pyenv-latest @@ -35,6 +35,12 @@ IFS=$'\n' else DEFINITION_CANDIDATES=( $(python-build --definitions ) ) fi + + if printf '%s\n' "${DEFINITION_CANDIDATES[@]}" | grep -qxFe "$prefix"; then + echo "$prefix" + exit $exitcode; + fi + # https://stackoverflow.com/questions/11856054/is-there-an-easy-way-to-pass-a-raw-string-to-grep/63483807#63483807 prefix_re="$(sed 's/[^\^]/[&]/g;s/[\^]/\\&/g' <<< "$prefix")" # FIXME: more reliable and readable would probably be to loop over them and transform in pure Bash diff --git a/test/latest.bats b/test/latest.bats index e3d2f445..31474786 100644 --- a/test/latest.bats +++ b/test/latest.bats @@ -64,6 +64,21 @@ pyenv: no known versions match the prefix \`3.8' ! } +@test "complete name resolves to itself" { + create_executable pyenv-versions <