Skip to content

Commit 9401977

Browse files
authored
Elide the looong value in the exception message.
1 parent b524ecd commit 9401977

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

Lib/ipaddress.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1661,7 +1661,8 @@ def _ip_int_from_string(cls, ip_str):
16611661
if not ip_str:
16621662
raise AddressValueError('Address cannot be empty')
16631663
if len(ip_str) > 39:
1664-
msg = "At most 39 characters expected in %r" % (ip_str,)
1664+
msg = ("At most 39 characters expected in "
1665+
f"{ip_str[:14]!r}({len(ip_str)-28} chars elided){ip_str[-14:]!r}")
16651666
raise AddressValueError(msg)
16661667

16671668
# We want to allow more parts than the max to be 'split'

Lib/test/test_ipaddress.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,8 @@ def assertBadSplit(addr):
399399

400400
def test_bad_address_split_v6_too_long(self):
401401
def assertBadSplit(addr):
402-
msg = "At most 39 characters expected in %r"
403-
with self.assertAddressError(msg, addr.split('%')[0]):
402+
msg = r"At most 39 characters expected in %s"
403+
with self.assertAddressError(msg, repr(re.escape(addr[:14]))):
404404
ipaddress.IPv6Address(addr)
405405

406406
# Long IPv6 address
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Short-circuit the processing of long IPv6 addresses early to prevent excessive
1+
Short-circuit the processing of long IPv6 addresses early in :mod:`ipaddress` to prevent excessive
22
memory consumption and a minor denial-of-service.

0 commit comments

Comments
 (0)