From 7993203aa6bce6f3ca13a48c03caeab19f2fae5e Mon Sep 17 00:00:00 2001 From: Zhuyuyangyy <193758752+Zhuyuyangyy@users.noreply.github.com> Date: Fri, 23 Oct 2026 17:34:52 +0800 Subject: [PATCH] Fix 63-character limit for simple hostname labels --- src/validators/hostname.py | 6 +++--- tests/test_hostname.py | 13 +++++++++++++ tests/test_url.py | 11 +++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/validators/hostname.py b/src/validators/hostname.py index e34ab7e4..c99a00f3 100644 --- a/src/validators/hostname.py +++ b/src/validators/hostname.py @@ -24,10 +24,10 @@ def _port_regex(): @lru_cache def _simple_hostname_regex(): """Simple hostname validation regex.""" - # {0,59} because two characters are already matched at - # the beginning and at the end, making the range {1, 61} + # RFC 1035 limits each label to 63 octets. The first and last + # characters leave room for up to 61 characters in between. return re.compile( - r"^(?!-)[a-z0-9](?:[a-z0-9-]{0,59}[a-z0-9])?(?