thombashi / pathvalidate

A Python library to sanitize/validate a string such as filenames/file-paths/etc.
https://pathvalidate.rtfd.io/
MIT License
220 stars 13 forks source link

validate_filepath_arg claims '/path/to/somewhere.txt' invalid #11

Closed freelanceAndy closed 4 years ago

freelanceAndy commented 4 years ago

Using Python 3.6.9 with pathvalidate 2.1.0:

import argparse
from pathvalidate.argparse import validate_filename_arg, validate_filepath_arg

parser = argparse.ArgumentParser()
parser.add_argument('--s3-bucket', type=str, help='check authentication repo for bucket names')
parser.add_argument('--input-path', type=validate_filepath_arg)
parser.add_argument('--output-path', type=validate_filepath_arg)
args = parser.parse_args(['download', '--s3-bucket', 'default', '--input-path', '/path/to/somewhere.txt', '--output-path', '/path/to/somewhere.txt'])

python3 example_bug.py usage: example_bug.py [-h] [--s3-bucket S3_BUCKET] [--input-path INPUT_PATH] [--output-path OUTPUT_PATH] example_bug.py: error: argument --input-path: reason=MALFORMED_ABS_PATH, target-platform=universal, description=an invalid absolute file path (/path/to/somewhere.txt) for the platform (universal). specify an appropriate platform or 'auto'.

The error is raised in: def validate_abspath(self, value: PathType) -> None: ...

       if self._is_universal() and any([is_posix_abs, is_nt_abs]):
           raise err_object
thombashi commented 4 years ago

@freelanceAndy Thank you for your report.

Please try to upgrade pathvalidate package to 2.2.0 and re-execute. I believe the latest version fixed the issue.

freelanceAndy commented 4 years ago

Thanks for your swift response! Works great now.