Skip to content

Commit

Permalink
Merge Update parse_domain regex (#9)
Browse files Browse the repository at this point in the history
This change allows for the parse_domain function to capture root domains containing hyphens and periods.
  • Loading branch information
rodriguhe authored Dec 9, 2023
1 parent 50a87b2 commit b62d6c9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions magento/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ def parse_domain(domain: str):
>>> parse_domain('https://www.mymagento.com/')
'mymagento.com'
>>> parse_domain('https://www.my-magento.magento.com/')
'my-magento.magento.com'
"""
match = re.match(
pattern=r"(?:https?://)?(?:w{,3}\.)?([\w\./]+?)/?$",
pattern=r"^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n?]+)",
string=domain
)
if match:
return match.group(1).rstrip('/')
return match.group(1)
raise ValueError("Invalid format provided for ``domain``")


Expand Down

0 comments on commit b62d6c9

Please sign in to comment.