Skip to content

Commit 84c28d4

Browse files
committed
fix: reject an underscore in the last domain label
The last label allowed "_" with or without rfc_2782, so foo.ba_r validated.
1 parent 70de324 commit 84c28d4

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎CHANGES.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ Note to self: Breaking changes must increment either
99
1010
-->
1111

12+
## Unreleased
13+
14+
_**Fixes**_
15+
16+
* Reject an underscore in the last domain label. ([#484](https://github.com/python-validators/validators/issues/484))
17+
1218
## 0.35.0 (2025-05-01)
1319

1420
_**Breaking**_ ⚠️

‎src/validators/domain.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ def domain(
9090
+ rf"(?:[a-z0-9-{service_record}]{{0,61}}"
9191
# Hostname
9292
+ rf"[a-z0-9{service_record}])?\.)"
93-
# First 61 characters of the gTLD
94-
+ r"+[a-z0-9][a-z0-9-_]{0,61}"
93+
# First 61 characters of the gTLD. An underscore belongs
94+
# in a service label, not here.
95+
+ r"+[a-z0-9][a-z0-9-]{0,61}"
9596
# Last character of the gTLD
9697
+ rf"[a-z]{trailing_dot}",
9798
value.encode("idna").decode("utf-8"),

‎tests/test_domain.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ def test_returns_true_on_valid_top_level_domain(
7474
("__exa__mple__.com", False, True),
7575
("a......b.com", False, False),
7676
("a.123", False, False),
77+
("foo.ba_r", False, False),
78+
("foo.ba_r", False, True),
79+
("example.co_uk", False, False),
7780
("123.123", False, False),
7881
("123.123.123.", True, False),
7982
("123.123.123.123", False, False),

0 commit comments

Comments
 (0)