gitignore_parser icon indicating copy to clipboard operation
gitignore_parser copied to clipboard

ValueError raised on symlinks that point to a different path

Open presto8 opened this issue 5 years ago • 2 comments

I have a file that is a symbolic link to another location, e.g., /one/two/three -> /four/five/six. When using parse_gitignore on the symlink path (/one/two/three) it throws a ValueError:

raise ValueError("{!r} is not in the subpath of {!r}"

I believe it's caused by this line:

rel_path = str(Path(abs_path).resolve().relative_to(self.base_path))

According to the Path() documentation, resolve() will follow symlinks and remove "..". Was this intentional behavior to resolve symlinks? If so, some additional logic may be needed to catch this situation.

presto8 avatar Dec 24 '20 04:12 presto8

I'll be happy to accept a PR that fixes this in a standard-compliant way :-)

mherrmann avatar Dec 28 '20 06:12 mherrmann

change resolve() to absolute() I believe would solve the problem. But I feel absolute() is not officially supported as I cannot find it in the latest doc of pathlib.

yilun-wu avatar Apr 29 '22 12:04 yilun-wu