Skip to content

Commit 439cc28

Browse files
committed
Fix improper validation in file:<location> syntax
1 parent 972b1d4 commit 439cc28

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

mangadex_downloader/cli/validator.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@ def _validate(url):
3131
raise argparse.ArgumentTypeError(str(e))
3232
return _url
3333

34-
def validate_url(url):
35-
if os.path.exists(url):
36-
with open(url, 'r') as opener:
37-
content = opener.read()
38-
else:
39-
content = url
34+
def _try_read(path):
35+
if not os.path.exists(path):
36+
return None
37+
38+
with open(path, 'r') as o:
39+
return o.read()
4040

41+
def validate_url(url):
4142
urls = []
42-
for _url in content.splitlines():
43+
for _url in url.splitlines():
4344
if not _url:
4445
continue
4546

@@ -245,7 +246,8 @@ def validate(parser, args):
245246
elif not os.path.exists(file_path):
246247
parser.error(f"File \"{file_path}\" is not exist")
247248
else:
248-
file_path = urls
249+
file_content = _try_read(urls)
250+
file_path = file_content if file_content is not None else urls
249251
try:
250252
args.URL = validate_url(file_path)
251253
except argparse.ArgumentTypeError as e:

0 commit comments

Comments
 (0)