Skip to content
Permalink
Browse files Browse the repository at this point in the history
Fix improper validation in file:<location> syntax
  • Loading branch information
mansuf committed Sep 4, 2022
1 parent 972b1d4 commit 439cc28
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions mangadex_downloader/cli/validator.py
Expand Up @@ -31,15 +31,16 @@ def _validate(url):
raise argparse.ArgumentTypeError(str(e))
return _url

def validate_url(url):
if os.path.exists(url):
with open(url, 'r') as opener:
content = opener.read()
else:
content = url
def _try_read(path):
if not os.path.exists(path):
return None

with open(path, 'r') as o:
return o.read()

def validate_url(url):
urls = []
for _url in content.splitlines():
for _url in url.splitlines():
if not _url:
continue

Expand Down Expand Up @@ -245,7 +246,8 @@ def validate(parser, args):
elif not os.path.exists(file_path):
parser.error(f"File \"{file_path}\" is not exist")
else:
file_path = urls
file_content = _try_read(urls)
file_path = file_content if file_content is not None else urls
try:
args.URL = validate_url(file_path)
except argparse.ArgumentTypeError as e:
Expand Down

0 comments on commit 439cc28

Please sign in to comment.