summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/click/types.py10
-rw-r--r--tests/test_types.py11
2 files changed, 16 insertions, 5 deletions
diff --git a/src/click/types.py b/src/click/types.py
index cd39469..a7de43b 100644
--- a/src/click/types.py
+++ b/src/click/types.py
@@ -845,11 +845,11 @@ class Path(ParamType):
if os.path.islink(rv):
rv = os.readlink(rv)
- # Join dir_ with the resolved symlink. If the resolved
- # path is relative, this will make it relative to the
- # original containing directory. If it is absolute, this
- # has no effect.
- rv = os.path.join(dir_, rv)
+ # Join dir_ with the resolved symlink if the resolved
+ # path is relative. This will make it relative to the
+ # original containing directory.
+ if not os.path.isabs(rv):
+ rv = os.path.join(dir_, rv)
try:
st = os.stat(rv)
diff --git a/tests/test_types.py b/tests/test_types.py
index 58d1b68..dff8172 100644
--- a/tests/test_types.py
+++ b/tests/test_types.py
@@ -126,4 +126,15 @@ def test_symlink_resolution(tmpdir, sym_file, abs_fun):
# test
ctx = click.Context(click.Command("do_stuff"))
rv = click.Path(resolve_path=True).convert(sym_path, None, ctx)
+
+ # os.readlink prepends path prefixes to absolute
+ # links in windows.
+ # https://docs.microsoft.com/en-us/windows/win32/
+ # ... fileio/naming-a-file#win32-file-namespaces
+ #
+ # Here we strip win32 path prefix from the resolved path
+ rv_drive, rv_path = os.path.splitdrive(rv)
+ stripped_rv_drive = rv_drive.split(os.path.sep)[-1]
+ rv = os.path.join(stripped_rv_drive, rv_path)
+
assert rv == real_path