Merge pull request #4838 from clayarnoldg2m/fix/4711-symlink-loop

fix: handle symlink loops in safe_abs_path()
This commit is contained in:
paul-gauthier
2026-02-16 08:26:13 -08:00
committed by GitHub
2 changed files with 19 additions and 1 deletions

View File

@@ -95,7 +95,10 @@ def is_image_file(file_name):
def safe_abs_path(res): def safe_abs_path(res):
"Gives an abs path, which safely returns a full (not 8.3) windows path" "Gives an abs path, which safely returns a full (not 8.3) windows path"
res = Path(res).resolve() try:
res = Path(res).resolve()
except (RuntimeError, OSError):
res = Path(res).absolute()
return str(res) return str(res)

15
tests/basic/test_utils.py Normal file
View File

@@ -0,0 +1,15 @@
import os
from aider.utils import safe_abs_path
def test_safe_abs_path_symlink_loop(tmp_path):
# Create circular symlink: a -> b -> a
link_a = tmp_path / "link_a"
link_b = tmp_path / "link_b"
link_a.symlink_to(link_b)
link_b.symlink_to(link_a)
# safe_abs_path must not raise, and must return an absolute path
result = safe_abs_path(str(link_a))
assert os.path.isabs(result)