Index: trunk/phase3/maintenance/tests/phpunit/includes/IPTest.php |
— | — | @@ -35,6 +35,7 @@ |
36 | 36 | public function testisIPv6() { |
37 | 37 | $this->assertFalse( IP::isIPv6( ':fc:100::' ), 'IPv6 starting with lone ":"' ); |
38 | 38 | $this->assertFalse( IP::isIPv6( 'fc:100:::' ), 'IPv6 ending with a ":::"' ); |
| 39 | + $this->assertFalse( IP::isIPv6( 'fc:300' ), 'IPv6 with only 2 words' ); |
39 | 40 | $this->assertFalse( IP::isIPv6( 'fc:100:300' ), 'IPv6 with only 3 words' ); |
40 | 41 | $this->assertTrue( IP::isIPv6( 'fc:100::' ) ); |
41 | 42 | $this->assertTrue( IP::isIPv6( 'fc:100:a::' ) ); |
— | — | @@ -62,12 +63,12 @@ |
63 | 64 | $this->assertFalse( IP::isIPv6( ':fc::100' ), 'IPv6 starting with lone ":"' ); |
64 | 65 | $this->assertFalse( IP::isIPv6( 'fc::100:' ), 'IPv6 ending with lone ":"' ); |
65 | 66 | $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' ); |
72 | 73 | $this->assertFalse( IP::isIPv6( 'fc::100:a:d:1:e:ac:0' ), 'IPv6 with "::" and 8 words' ); |
73 | 74 | $this->assertFalse( IP::isIPv6( 'fc::100:a:d:1:e:ac:0:1' ), 'IPv6 with 9 words' ); |
74 | 75 | |
Index: trunk/phase3/includes/IP.php |
— | — | @@ -35,17 +35,19 @@ |
36 | 36 | define( 'RE_IPV6_WORD', '([0-9A-Fa-f]{1,4})' ); |
37 | 37 | define( 'RE_IPV6_PREFIX', '(12[0-8]|1[01][0-9]|[1-9]?\d)'); |
38 | 38 | 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 "::") |
42 | 42 | RE_IPV6_WORD . '(?::' . RE_IPV6_WORD . '){0,6}::' . |
43 | | - '|' . // has no "::" |
| 43 | + '|' . // contains no "::" |
44 | 44 | 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)' . |
47 | 50 | // 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: |
50 | 52 | #RE_IPV6_WORD . '(?::((?(-1)|:))?' . RE_IPV6_WORD . '){1,6}(?(-2)|^)' . |
51 | 53 | ')' |
52 | 54 | ); |