Skip to content

8.0.2 doesn't validate paths correctly #2088

@dylwylie

Description

@dylwylie

Path arguments with a directory fail validation with "file not exists", despite existing, when resolve_path=True is specified

It looks like the code here concats the passed-in-path to its resolved directory, which means if the path contains a directory, the directory part gets duplicated

rv = os.path.join(dir_, rv)

e.g.

$ touch relative-dir/myfile
$ python3
Python 3.9.7 (default, Sep 28 2021, 18:41:28)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from click import Path
>>> p = Path(dir_okay=False, exists=True, writable=False, resolve_path=True)
>>> p.convert("relative-dir/myfile", None, None)
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/click/types.py", line 855, in convert
    st = os.stat(rv)
FileNotFoundError: [Errno 2] No such file or directory: '/relative-dir/relative-dir/myfile'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/click/types.py", line 859, in convert
    self.fail(
  File "/usr/local/lib/python3.9/site-packages/click/types.py", line 128, in fail
    raise BadParameter(message, ctx=ctx, param=param)
click.exceptions.BadParameter: File 'relative-dir/myfile' does not exist.

Environment:

  • Python version: 3.9.7
  • Click version: 8.0.2

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions