File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -210,10 +210,12 @@ def cel_is_hostname(val: object) -> bool:
210210
211211def _is_hostname (val : str ) -> bool :
212212 """Internal implementation."""
213- if len (val ) > 253 :
214- return False
213+ string = val .removesuffix ("." ).lower ()
215214
216- string = val [0 : len (val ) - 1 ].lower () if val .endswith ("." ) else val .lower ()
215+ # The 253-character limit excludes the optional trailing dot (RFC 3339) which
216+ # we just stripped.
217+ if len (string ) > 253 :
218+ return False
217219
218220 all_digits = False
219221 parts = string .lower ().split (sep = "." )
Original file line number Diff line number Diff line change 1+ # Copyright (c) 2023-2026 Buf Technologies, Inc.
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+
15+ from __future__ import annotations
16+
17+ from protovalidate ._funcs import _is_hostname
18+
19+
20+ def test_hostname_trailing_dot_excluded_from_length () -> None :
21+ name253 = ("a" * 63 + "." ) * 3 + "a" * 61
22+ name254 = ("a" * 63 + "." ) * 3 + "a" * 62
23+ assert len (name253 ) == 253
24+ assert len (name254 ) == 254
25+ # The 253-character limit excludes the optional trailing dot (RFC 3339).
26+ assert _is_hostname (name253 )
27+ assert _is_hostname (name253 + "." )
28+ assert not _is_hostname (name254 )
29+ assert not _is_hostname (name254 + "." )
You can’t perform that action at this time.
0 commit comments