Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-36384: Remove check for leading zeroes in IPv4 addresses #12577

Merged
merged 3 commits into from
Mar 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions Lib/ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -1165,12 +1165,6 @@ def _parse_octet(cls, octet_str):
raise ValueError(msg % octet_str)
# Convert to integer (we know digits are legal)
octet_int = int(octet_str, 10)
# Any octets that look like they *might* be written in octal,
# and which don't look exactly the same in both octal and
# decimal are rejected as ambiguous
if octet_int > 7 and octet_str[0] == '0':
msg = "Ambiguous (octal/decimal) value in %r not permitted"
raise ValueError(msg % octet_str)
if octet_int > 255:
raise ValueError("Octet %d (> 255) not permitted" % octet_int)
return octet_int
Expand Down
12 changes: 3 additions & 9 deletions Lib/test/test_ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,14 @@ def pickle_test(self, addr):
y = pickle.loads(pickle.dumps(x, proto))
self.assertEqual(y, x)


class CommonTestMixin_v4(CommonTestMixin):

def test_leading_zeros(self):
self.assertInstancesEqual("000.000.000.000", "0.0.0.0")
self.assertInstancesEqual("192.168.000.001", "192.168.0.1")
self.assertInstancesEqual("016.016.016.016", "16.16.16.16")
self.assertInstancesEqual("001.000.008.016", "1.0.8.16")

def test_int(self):
self.assertInstancesEqual(0, "0.0.0.0")
Expand Down Expand Up @@ -229,15 +232,6 @@ def assertBadOctet(addr, octet):
assertBadOctet("1.2.3.4::", "4::")
assertBadOctet("1.a.2.3", "a")

def test_octal_decimal_ambiguity(self):
def assertBadOctet(addr, octet):
msg = "Ambiguous (octal/decimal) value in %r not permitted in %r"
with self.assertAddressError(re.escape(msg % (octet, addr))):
ipaddress.IPv4Address(addr)

assertBadOctet("016.016.016.016", "016")
assertBadOctet("001.000.008.016", "008")

def test_octet_length(self):
def assertBadOctet(addr, octet):
msg = "At most 3 characters permitted in %r in %r"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Stop rejecting IPv4 octets for being ambiguously octal. Leading zeros are ignored, and no longer are assumed to specify octal octets. Octets are always decimal numbers. Octets must still be no more than three digits, including leading zeroes.