Improving is_valid_path

This commit is contained in:
José Manuel Barroso Galindo
2023-04-12 01:10:15 +02:00
committed by GitHub
parent 2cc3c5a130
commit a0389fb98f

View File

@@ -201,7 +201,15 @@ def is_valid_url(url: str) -> bool:
def is_valid_path(path: str) -> bool:
try:
return Path(path).is_relative() and len(path) >= 3
p = Path(path)
if not p.is_relative() or len(path) < 3:
return False
for part in p.parts:
if part in ['..', '.']:
return False
return True
except Exception:
return False