From aaba8388d77215d6b57ecc8606d26ff9e7c37dbf Mon Sep 17 00:00:00 2001 From: root Date: Tue, 26 Mar 2019 19:01:14 -0700 Subject: [PATCH 1/3] bpo-36384: Remove check for leading zeroes in IPv4 addresses Stop rejecting IPv4 octets with leading zeroes as ambiguously octal. https://bugs.python.org/issue36384 --- Lib/ipaddress.py | 6 ------ Lib/test/test_ipaddress.py | 12 +++--------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py index 15507d61dec8f9..a88cf3d0b7c5d6 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -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 diff --git a/Lib/test/test_ipaddress.py b/Lib/test/test_ipaddress.py index 0e0753f34c4905..53f6f128443c52 100644 --- a/Lib/test/test_ipaddress.py +++ b/Lib/test/test_ipaddress.py @@ -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") @@ -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" From 54bb4ffa61d3d7aefd1b315d197ea43aa80977d8 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" Date: Wed, 27 Mar 2019 02:09:23 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Library/2019-03-27-02-09-22.bpo-36385.we2F45.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2019-03-27-02-09-22.bpo-36385.we2F45.rst diff --git a/Misc/NEWS.d/next/Library/2019-03-27-02-09-22.bpo-36385.we2F45.rst b/Misc/NEWS.d/next/Library/2019-03-27-02-09-22.bpo-36385.we2F45.rst new file mode 100644 index 00000000000000..b3a1f2621f9b4f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-03-27-02-09-22.bpo-36385.we2F45.rst @@ -0,0 +1 @@ +Stop rejecting IPv4 octets for leading zeroes. \ No newline at end of file From cbd50fa99f7137b05d271715540e614106042a25 Mon Sep 17 00:00:00 2001 From: Joel Croteau Date: Wed, 27 Mar 2019 09:50:48 -0700 Subject: [PATCH 3/3] Update 2019-03-27-02-09-22.bpo-36385.we2F45.rst Provide a more detailed description of the behavior change to `ipaddress`. --- .../next/Library/2019-03-27-02-09-22.bpo-36385.we2F45.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2019-03-27-02-09-22.bpo-36385.we2F45.rst b/Misc/NEWS.d/next/Library/2019-03-27-02-09-22.bpo-36385.we2F45.rst index b3a1f2621f9b4f..26f6dd7d5f47e2 100644 --- a/Misc/NEWS.d/next/Library/2019-03-27-02-09-22.bpo-36385.we2F45.rst +++ b/Misc/NEWS.d/next/Library/2019-03-27-02-09-22.bpo-36385.we2F45.rst @@ -1 +1 @@ -Stop rejecting IPv4 octets for leading zeroes. \ No newline at end of file +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.