small fixes (no protocol requirement for isonion, bool return types)

This commit is contained in:
oxeo0 2025-05-30 02:31:35 +02:00
parent c9a2fbcfdd
commit 4f1e6dbbc8
2 changed files with 8 additions and 6 deletions

View file

@ -25,8 +25,9 @@ CLEARNET_URL_PATTERN = re.compile(
)
# pattern for onion urls (56 bytes of base32 alphabet + .onion)
# it works also without http(s)://, so just the hostname will also go through
ONION_URL_PATTERN = re.compile(
r"^https?:\/\/([a-zA-Z0-9-]+\.)*[a-z2-7-]{56}\.onion[^\s]*$"
r"^(https?:\/\/)?([a-zA-Z0-9-]+\.)*[a-z2-7-]{56}\.onion[^\s]*$"
)
# pattern for simplex chatroom links
@ -49,7 +50,7 @@ def IsSimplexChatroomValid(url: str) -> bool:
Returns True if URL is a SimpleX chatroom,
False otherwise
"""
return SIMPLEX_CHATROOM_PATTERN.match(url)
return bool(SIMPLEX_CHATROOM_PATTERN.match(url))
def RecognizeSimplexType(url: str) -> str:
"""
@ -82,14 +83,14 @@ def IsClearnetLinkValid(url: str) -> bool:
Returns True if URL is a valid clearnet URL
False otherwise
"""
return CLEARNET_URL_PATTERN.match(url)
return bool(CLEARNET_URL_PATTERN.match(url))
def IsOnionLinkValid(url: str) -> bool:
"""
Returns True if URL is a valid onion URL
False otherwise
"""
return ONION_URL_PATTERN.match(url)
return bool(ONION_URL_PATTERN.match(url))
def RecognizeURLType(url: str) -> str:
"""