fix simplex parsing

This commit is contained in:
cynthia 2025-04-14 23:26:46 +01:00
parent 13d39dc5c2
commit 013673fffb
2 changed files with 9 additions and 6 deletions

View file

@ -6,6 +6,7 @@ def IsOnionValid(url: str)-> bool:
"""
try:
pattern = re.compile(r"^[A-Za-z0-9:/._%-=#?&@]+(.onion)$")
url_pattern = re.compile(r"^(\w+:)?(?://)?(\w+\.)?[a-z2-7]{56}\.onion")
url = url.strip().removesuffix('/')
if url.startswith('http://'):
domain = url.split('/')[2]
@ -22,14 +23,14 @@ def IsOnionValid(url: str)-> bool:
return False
else:
#TODO : edit the url to make sure it has http:// at the beginning, in case if it's missing? (problem is that it only returns true or false)
if pattern.fullmatch(url) is not None:
if url_pattern.match(url) is not None:
if len(url.split('.')) > 3:
return False
else:
if len(url) < 62:
return False
return True
elif pattern.fullmatch(url) is None:
elif url_pattern.match(url) is None:
return False
else:
return False
@ -41,10 +42,11 @@ def IsUrlValid(url:str)->bool:
Check if url is valid both dark net end clearnet.
"""
pattern = re.compile(r"^[A-Za-z0-9:/._%-=#?&@]+$")
onion_pattern = re.compile(r"^(\w+:)?(?://)?(\w+\.)?[a-z2-7]{56}\.onion")
url = str(url)
if len(url) < 4:
return False
if url.endswith('.onion'):
if onion_pattern.match(url) is not None:
return IsOnionValid(url)
else:
if not url.__contains__('.'):