bpo-36384: Remove check for leading zeroes in IPv4 addresses (GH-12577) · python/cpython@e653d4d (original) (raw)
3 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1165,12 +1165,6 @@ def _parse_octet(cls, octet_str): | ||
1165 | 1165 | raise ValueError(msg % octet_str) |
1166 | 1166 | # Convert to integer (we know digits are legal) |
1167 | 1167 | octet_int = int(octet_str, 10) |
1168 | -# Any octets that look like they *might* be written in octal, | |
1169 | -# and which don't look exactly the same in both octal and | |
1170 | -# decimal are rejected as ambiguous | |
1171 | -if octet_int > 7 and octet_str[0] == '0': | |
1172 | -msg = "Ambiguous (octal/decimal) value in %r not permitted" | |
1173 | -raise ValueError(msg % octet_str) | |
1174 | 1168 | if octet_int > 255: |
1175 | 1169 | raise ValueError("Octet %d (> 255) not permitted" % octet_int) |
1176 | 1170 | return octet_int |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -92,11 +92,14 @@ def pickle_test(self, addr): | ||
92 | 92 | y = pickle.loads(pickle.dumps(x, proto)) |
93 | 93 | self.assertEqual(y, x) |
94 | 94 | |
95 | + | |
95 | 96 | class CommonTestMixin_v4(CommonTestMixin): |
96 | 97 | |
97 | 98 | def test_leading_zeros(self): |
98 | 99 | self.assertInstancesEqual("000.000.000.000", "0.0.0.0") |
99 | 100 | self.assertInstancesEqual("192.168.000.001", "192.168.0.1") |
101 | +self.assertInstancesEqual("016.016.016.016", "16.16.16.16") | |
102 | +self.assertInstancesEqual("001.000.008.016", "1.0.8.16") | |
100 | 103 | |
101 | 104 | def test_int(self): |
102 | 105 | self.assertInstancesEqual(0, "0.0.0.0") |
@@ -229,15 +232,6 @@ def assertBadOctet(addr, octet): | ||
229 | 232 | assertBadOctet("1.2.3.4::", "4::") |
230 | 233 | assertBadOctet("1.a.2.3", "a") |
231 | 234 | |
232 | -def test_octal_decimal_ambiguity(self): | |
233 | -def assertBadOctet(addr, octet): | |
234 | -msg = "Ambiguous (octal/decimal) value in %r not permitted in %r" | |
235 | -with self.assertAddressError(re.escape(msg % (octet, addr))): | |
236 | -ipaddress.IPv4Address(addr) | |
237 | - | |
238 | -assertBadOctet("016.016.016.016", "016") | |
239 | -assertBadOctet("001.000.008.016", "008") | |
240 | - | |
241 | 235 | def test_octet_length(self): |
242 | 236 | def assertBadOctet(addr, octet): |
243 | 237 | msg = "At most 3 characters permitted in %r in %r" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
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. |