r77067 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77066‎ | r77067 | r77068 >
Date:10:49, 21 November 2010
Author:aaron
Status:resolved (Comments)
Tags:needs-php-test 
Comment:
*(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
Modified paths:
  • /trunk/phase3/includes/IP.php (modified) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/IPTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/tests/phpunit/includes/IPTest.php
@@ -35,6 +35,7 @@
3636 public function testisIPv6() {
3737 $this->assertFalse( IP::isIPv6( ':fc:100::' ), 'IPv6 starting with lone ":"' );
3838 $this->assertFalse( IP::isIPv6( 'fc:100:::' ), 'IPv6 ending with a ":::"' );
 39+ $this->assertFalse( IP::isIPv6( 'fc:300' ), 'IPv6 with only 2 words' );
3940 $this->assertFalse( IP::isIPv6( 'fc:100:300' ), 'IPv6 with only 3 words' );
4041 $this->assertTrue( IP::isIPv6( 'fc:100::' ) );
4142 $this->assertTrue( IP::isIPv6( 'fc:100:a::' ) );
@@ -62,12 +63,12 @@
6364 $this->assertFalse( IP::isIPv6( ':fc::100' ), 'IPv6 starting with lone ":"' );
6465 $this->assertFalse( IP::isIPv6( 'fc::100:' ), 'IPv6 ending with lone ":"' );
6566 $this->assertFalse( IP::isIPv6( 'fc:::100' ), 'IPv6 with ":::" in the middle' );
66 - $this->assertTrue( IP::isIPv6( 'fc::100' ) );
67 - $this->assertTrue( IP::isIPv6( 'fc::100:a' ) );
68 - $this->assertTrue( IP::isIPv6( 'fc::100:a:d' ) );
69 - $this->assertTrue( IP::isIPv6( 'fc::100:a:d:1' ) );
70 - $this->assertTrue( IP::isIPv6( 'fc::100:a:d:1:e' ) );
71 - $this->assertTrue( IP::isIPv6( 'fc::100:a:d:1:e:ac' ) );
 67+ $this->assertTrue( IP::isIPv6( 'fc::100' ), 'IPv6 with "::" and 2 words' );
 68+ $this->assertTrue( IP::isIPv6( 'fc::100:a' ), 'IPv6 with "::" and 3 words' );
 69+ $this->assertTrue( IP::isIPv6( 'fc::100:a:d', 'IPv6 with "::" and 4 words' ) );
 70+ $this->assertTrue( IP::isIPv6( 'fc::100:a:d:1' ), 'IPv6 with "::" and 5 words' );
 71+ $this->assertTrue( IP::isIPv6( 'fc::100:a:d:1:e' ), 'IPv6 with "::" and 6 words' );
 72+ $this->assertTrue( IP::isIPv6( 'fc::100:a:d:1:e:ac' ), 'IPv6 with "::" and 7 words' );
7273 $this->assertFalse( IP::isIPv6( 'fc::100:a:d:1:e:ac:0' ), 'IPv6 with "::" and 8 words' );
7374 $this->assertFalse( IP::isIPv6( 'fc::100:a:d:1:e:ac:0:1' ), 'IPv6 with 9 words' );
7475
Index: trunk/phase3/includes/IP.php
@@ -35,17 +35,19 @@
3636 define( 'RE_IPV6_WORD', '([0-9A-Fa-f]{1,4})' );
3737 define( 'RE_IPV6_PREFIX', '(12[0-8]|1[01][0-9]|[1-9]?\d)');
3838 define( 'RE_IPV6_ADD',
39 - '(?:' . // starts with "::" (includes the address "::")
40 - '::|:(?::' . RE_IPV6_WORD . '){1,7}' .
41 - '|' . // ends with "::" (not including the address "::")
 39+ '(?:' . // starts with "::" (including "::")
 40+ ':(?::|(?::' . RE_IPV6_WORD . '){1,7})' .
 41+ '|' . // ends with "::" (except "::")
4242 RE_IPV6_WORD . '(?::' . RE_IPV6_WORD . '){0,6}::' .
43 - '|' . // has no "::"
 43+ '|' . // contains no "::"
4444 RE_IPV6_WORD . '(?::' . RE_IPV6_WORD . '){7}' .
45 - '|' . // contains one "::" in the middle (awkward regex for PCRE 4.0+ compatibility)
46 - RE_IPV6_WORD . '(?::(?!(?P=abn))(?P<abn>:(?P<iabn>))?' . RE_IPV6_WORD . '){1,6}(?P=iabn)' .
 45+ '|' . // contains one "::" in the middle and 2 words
 46+ RE_IPV6_WORD . '::' . RE_IPV6_WORD .
 47+ '|' . // contains one "::" in the middle and 3+ words (awkward regex for PCRE 4.0+)
 48+ RE_IPV6_WORD . '(?::(?P<abn>:(?P<iabn>))?' . RE_IPV6_WORD . '(?!:(?P=abn))){1,5}' .
 49+ ':' . RE_IPV6_WORD . '(?P=iabn)' .
4750 // NOTE: (?!(?P=abn)) fails iff "::" used twice; (?P=iabn) passes iff a "::" was found.
48 -
49 - // Better regexp (PCRE 7.2+ only), allows intuitive regex concatenation
 51+ // RegExp (PCRE 7.2+ only) for last 2 cases that allows easy regex concatenation:
5052 #RE_IPV6_WORD . '(?::((?(-1)|:))?' . RE_IPV6_WORD . '){1,6}(?(-2)|^)' .
5153 ')'
5254 );

Follow-up revisions

RevisionCommit summaryAuthorDate
r82093* (bug 27353) IPv6 address ending in "::WORD" was not recognized...aaron23:24, 13 February 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r76876* Reduced some pointless regex capture overhead...aaron09:12, 17 November 2010
r76928(bug 25920) Moved forward ref to a nested ref to really get v6 regex to compi...aaron00:25, 18 November 2010

Comments

#Comment by Brion VIBBER (talk | contribs)   21:39, 13 February 2011

Causes regression bugzilla:27353

Status & tagging log