Fix resolution of a name that's a prefix of another name (#2521)

This commit is contained in:
native-api 2022-11-10 04:46:14 +03:00 committed by GitHub
parent 904fe964b0
commit ed1083ec27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View file

@ -35,6 +35,12 @@ IFS=$'\n'
else else
DEFINITION_CANDIDATES=( $(python-build --definitions ) ) DEFINITION_CANDIDATES=( $(python-build --definitions ) )
fi 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 # 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")" 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 # FIXME: more reliable and readable would probably be to loop over them and transform in pure Bash

View file

@ -64,6 +64,21 @@ pyenv: no known versions match the prefix \`3.8'
! !
} }
@test "complete name resolves to itself" {
create_executable pyenv-versions <<!
#!$BASH
echo foo
echo foo.bar
!
run pyenv-latest foo
assert_success
assert_output <<!
foo
!
}
@test "sort CPython" { @test "sort CPython" {
create_executable pyenv-versions <<! create_executable pyenv-versions <<!
#!$BASH #!$BASH