mirror of
https://github.com/pyenv/pyenv.git
synced 2026-10-02 23:41:06 +09:00
version-file: Fix infinite loop for relative paths
find_local_version_file reduces its target with ${root%/*}, but that leaves a slash-less relative argument such as "." unchanged, leading to an infinite loop
Signed-off-by: 付典 <fudianchn@gmail.com>
This commit is contained in:
parent
b7e7adf4ec
commit
195b9fe940
@ -8,6 +8,9 @@ target_dir="$1"
|
||||
|
||||
find_local_version_file() {
|
||||
local root="$1"
|
||||
# Nonexistent paths are UB as of this writing.
|
||||
# Relative ones cause a failure but absolute ones don't
|
||||
[[ $root != /* ]] && root=$(CDPATH= cd -- "$root" && pwd)
|
||||
while ! [[ "$root" =~ ^//[^/]*$ ]]; do
|
||||
if [ -f "${root}/.python-version" ]; then
|
||||
echo "${root}/.python-version"
|
||||
|
||||
@ -73,3 +73,15 @@ create_file() {
|
||||
run pyenv-version-file "$PWD"
|
||||
assert_failure ""
|
||||
}
|
||||
|
||||
@test "walks up beyond cwd for a relative path" {
|
||||
create_file ".python-version"
|
||||
mkdir -p project/subdir
|
||||
cd project
|
||||
# Run with CPU-time limit because this used to loop forever
|
||||
run bash -c 'ulimit -t 5; pyenv-version-file .'
|
||||
assert_success "${PYENV_TEST_DIR}/.python-version"
|
||||
|
||||
run pyenv-version-file ./subdir
|
||||
assert_success "${PYENV_TEST_DIR}/.python-version"
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user