Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F159702
T97897.patch
hoo (Marius Hoch)
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Authored By
hoo
May 2 2015, 4:51 PM
2015-05-02 16:51:53 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
T97897.patch
View Options
From 6e7efe6cea9abf7c7818701097d9c47d79b68965 Mon Sep 17 00:00:00 2001
From: Marius Hoch <hoo@online.de>
Date: Sat, 2 May 2015 18:48:04 +0200
Subject: [PATCH] Fix IP::toHex for IPv4 addresses with a double/triple 0 block
Bug: T97897
Change-Id: I5c0a37be42ae2c5091ead487a6d19f6e0dd89b36
---
includes/utils/IP.php | 5 +++--
tests/phpunit/includes/utils/IPTest.php | 1 +
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/includes/utils/IP.php b/includes/utils/IP.php
index 4441236..2138daf 100644
--- a/includes/utils/IP.php
+++ b/includes/utils/IP.php
@@ -395,8 +395,9 @@ class IP {
if ( self::isIPv6( $ip ) ) {
$n = 'v6-' . self::IPv6ToRawHex( $ip );
} elseif ( self::isIPv4( $ip ) ) {
- // Bug 60035: an IP with leading 0's fails in ip2long sometimes (e.g. *.08)
- $ip = preg_replace( '/(?<=\.)0+(?=[1-9])/', '', $ip );
+ // T62035/T97897: An IP with leading 0's fails in ip2long sometimes (e.g. *.08),
+ // also double/triple 0 needs to be changed to just a single 0 for ip2long.
+ $ip = preg_replace( '/(?<=\.)0+(?=([1-9]|0\.))/', '', $ip );
$n = ip2long( $ip );
if ( $n < 0 ) {
$n += pow( 2, 32 );
diff --git a/tests/phpunit/includes/utils/IPTest.php b/tests/phpunit/includes/utils/IPTest.php
index acc9dfc..3a4f289 100644
--- a/tests/phpunit/includes/utils/IPTest.php
+++ b/tests/phpunit/includes/utils/IPTest.php
@@ -336,6 +336,7 @@ class IPTest extends PHPUnit_Framework_TestCase {
array( '80000000', '128.0.0.0' ),
array( 'DEADCAFE', '222.173.202.254' ),
array( 'FFFFFFFF', '255.255.255.255' ),
+ array( '8D000BFD', '141.000.11.253' ),
array( false, 'IN.VA.LI.D' ),
array( 'v6-00000000000000000000000000000001', '::1' ),
array( 'v6-20010DB885A3000000008A2E03707334', '2001:0db8:85a3:0000:0000:8a2e:0370:7334' ),
--
2.1.0
File Metadata
Details
Attached
Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
155389
Default Alt Text
T97897.patch (1 KB)
Attached To
Mode
T97897: Incorrect parsing of IPs for global block
Attached
Detach File
Event Timeline
Log In to Comment