Enhance domain validation by removing leading non-alphanumeric characters and refining www. prefix handling
Browse files
app.py
CHANGED
|
@@ -49,8 +49,12 @@ def validate_and_correct_domain(domain: str):
|
|
| 49 |
domain = domain.lower().strip('/').strip()
|
| 50 |
# extract domain
|
| 51 |
domain = urlparse(domain).netloc.strip() if '://' in domain else domain
|
|
|
|
|
|
|
|
|
|
| 52 |
# remove www.
|
| 53 |
-
|
|
|
|
| 54 |
# remove inner spaces
|
| 55 |
domain = re.sub(r'[\n\s]+', '', domain).strip()
|
| 56 |
# replace unwanted characters with hyphens
|
|
|
|
| 49 |
domain = domain.lower().strip('/').strip()
|
| 50 |
# extract domain
|
| 51 |
domain = urlparse(domain).netloc.strip() if '://' in domain else domain
|
| 52 |
+
# remove lending non alphanumeric
|
| 53 |
+
while domain and not domain[0].isalnum():
|
| 54 |
+
domain = domain[1:].strip()
|
| 55 |
# remove www.
|
| 56 |
+
if domain.startswith("www."):
|
| 57 |
+
domain = domain[4:].strip()
|
| 58 |
# remove inner spaces
|
| 59 |
domain = re.sub(r'[\n\s]+', '', domain).strip()
|
| 60 |
# replace unwanted characters with hyphens
|