From: Aaron Schulz Date: Sun, 21 Nov 2010 10:49:54 +0000 (+0000) Subject: *(bug 25920) Moved forward ref to a back ref to really get v6 regex to compile on... X-Git-Tag: 1.31.0-rc.0~33795 X-Git-Url: http://git.cyclocoop.org/data/%24oldEdit?a=commitdiff_plain;h=fb574da0ab628b14025d26045e136e05eb532676;p=lhc%2Fweb%2Fwiklou.git *(bug 25920) Moved forward ref to a back ref to really get v6 regex to compile on older PCRE versions. Works around PCRE 8 nested named ref bug that killed r76928. * Added another simple v6 assertion --- diff --git a/includes/IP.php b/includes/IP.php index 9aeba39f2c..9befb5974d 100644 --- a/includes/IP.php +++ b/includes/IP.php @@ -35,17 +35,19 @@ define( 'RE_IP_BLOCK', RE_IP_ADD . '\/' . RE_IP_PREFIX ); define( 'RE_IPV6_WORD', '([0-9A-Fa-f]{1,4})' ); define( 'RE_IPV6_PREFIX', '(12[0-8]|1[01][0-9]|[1-9]?\d)'); define( 'RE_IPV6_ADD', - '(?:' . // starts with "::" (includes the address "::") - '::|:(?::' . RE_IPV6_WORD . '){1,7}' . - '|' . // ends with "::" (not including the address "::") + '(?:' . // starts with "::" (including "::") + ':(?::|(?::' . RE_IPV6_WORD . '){1,7})' . + '|' . // ends with "::" (except "::") RE_IPV6_WORD . '(?::' . RE_IPV6_WORD . '){0,6}::' . - '|' . // has no "::" + '|' . // contains no "::" RE_IPV6_WORD . '(?::' . RE_IPV6_WORD . '){7}' . - '|' . // contains one "::" in the middle (awkward regex for PCRE 4.0+ compatibility) - RE_IPV6_WORD . '(?::(?!(?P=abn))(?P:(?P))?' . RE_IPV6_WORD . '){1,6}(?P=iabn)' . + '|' . // contains one "::" in the middle and 2 words + RE_IPV6_WORD . '::' . RE_IPV6_WORD . + '|' . // contains one "::" in the middle and 3+ words (awkward regex for PCRE 4.0+) + RE_IPV6_WORD . '(?::(?P:(?P))?' . RE_IPV6_WORD . '(?!:(?P=abn))){1,5}' . + ':' . RE_IPV6_WORD . '(?P=iabn)' . // NOTE: (?!(?P=abn)) fails iff "::" used twice; (?P=iabn) passes iff a "::" was found. - - // Better regexp (PCRE 7.2+ only), allows intuitive regex concatenation + // RegExp (PCRE 7.2+ only) for last 2 cases that allows easy regex concatenation: #RE_IPV6_WORD . '(?::((?(-1)|:))?' . RE_IPV6_WORD . '){1,6}(?(-2)|^)' . ')' ); diff --git a/maintenance/tests/phpunit/includes/IPTest.php b/maintenance/tests/phpunit/includes/IPTest.php index a409a10403..ff05ae285c 100644 --- a/maintenance/tests/phpunit/includes/IPTest.php +++ b/maintenance/tests/phpunit/includes/IPTest.php @@ -35,6 +35,7 @@ class IPTest extends PHPUnit_Framework_TestCase { public function testisIPv6() { $this->assertFalse( IP::isIPv6( ':fc:100::' ), 'IPv6 starting with lone ":"' ); $this->assertFalse( IP::isIPv6( 'fc:100:::' ), 'IPv6 ending with a ":::"' ); + $this->assertFalse( IP::isIPv6( 'fc:300' ), 'IPv6 with only 2 words' ); $this->assertFalse( IP::isIPv6( 'fc:100:300' ), 'IPv6 with only 3 words' ); $this->assertTrue( IP::isIPv6( 'fc:100::' ) ); $this->assertTrue( IP::isIPv6( 'fc:100:a::' ) ); @@ -62,12 +63,12 @@ class IPTest extends PHPUnit_Framework_TestCase { $this->assertFalse( IP::isIPv6( ':fc::100' ), 'IPv6 starting with lone ":"' ); $this->assertFalse( IP::isIPv6( 'fc::100:' ), 'IPv6 ending with lone ":"' ); $this->assertFalse( IP::isIPv6( 'fc:::100' ), 'IPv6 with ":::" in the middle' ); - $this->assertTrue( IP::isIPv6( 'fc::100' ) ); - $this->assertTrue( IP::isIPv6( 'fc::100:a' ) ); - $this->assertTrue( IP::isIPv6( 'fc::100:a:d' ) ); - $this->assertTrue( IP::isIPv6( 'fc::100:a:d:1' ) ); - $this->assertTrue( IP::isIPv6( 'fc::100:a:d:1:e' ) ); - $this->assertTrue( IP::isIPv6( 'fc::100:a:d:1:e:ac' ) ); + $this->assertTrue( IP::isIPv6( 'fc::100' ), 'IPv6 with "::" and 2 words' ); + $this->assertTrue( IP::isIPv6( 'fc::100:a' ), 'IPv6 with "::" and 3 words' ); + $this->assertTrue( IP::isIPv6( 'fc::100:a:d', 'IPv6 with "::" and 4 words' ) ); + $this->assertTrue( IP::isIPv6( 'fc::100:a:d:1' ), 'IPv6 with "::" and 5 words' ); + $this->assertTrue( IP::isIPv6( 'fc::100:a:d:1:e' ), 'IPv6 with "::" and 6 words' ); + $this->assertTrue( IP::isIPv6( 'fc::100:a:d:1:e:ac' ), 'IPv6 with "::" and 7 words' ); $this->assertFalse( IP::isIPv6( 'fc::100:a:d:1:e:ac:0' ), 'IPv6 with "::" and 8 words' ); $this->assertFalse( IP::isIPv6( 'fc::100:a:d:1:e:ac:0:1' ), 'IPv6 with 9 words' );