From 7097c630bdcce6f836963741b5984bfbf494c424 Mon Sep 17 00:00:00 2001 From: Timo Stamm Date: Tue, 15 Apr 2025 19:23:19 +0200 Subject: [PATCH] Fix isHostAndPort to reject leading zeros in port number --- protovalidate/internal/extra_func.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/protovalidate/internal/extra_func.py b/protovalidate/internal/extra_func.py index ceeb431f..950bbd1a 100644 --- a/protovalidate/internal/extra_func.py +++ b/protovalidate/internal/extra_func.py @@ -225,14 +225,13 @@ def _is_hostname(val: str) -> bool: def _is_port(val: str) -> bool: if len(val) == 0: return False - + if len(val) > 1 and val[0] == "0": + return False for c in val: if c < "0" or c > "9": return False - try: return int(val) <= 65535 - except ValueError: # Error converting to number return False