From: Aaron Schulz Date: Fri, 31 May 2013 23:12:18 +0000 (-0700) Subject: Simplified IPv6 regex per comment X-Git-Tag: 1.31.0-rc.0~18515 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=2d56adb39328ac086bed031bc47b1c1448ee1db5;p=lhc%2Fweb%2Fwiklou.git Simplified IPv6 regex per comment * We already require PHP 5.3.2, which includes PCRE 7.2+. PHP 5.2.4 includes PCRE 7.2 per http://php.net/ChangeLog-5.php. Change-Id: Ie9c1a0a93bef30a3a67e0140e621814351f8cea1 --- diff --git a/includes/IP.php b/includes/IP.php index fc76310aa8..73834a5950 100644 --- a/includes/IP.php +++ b/includes/IP.php @@ -39,18 +39,11 @@ define( 'RE_IPV6_ADD', ':(?::|(?::' . RE_IPV6_WORD . '){1,7})' . '|' . // ends with "::" (except "::") RE_IPV6_WORD . '(?::' . RE_IPV6_WORD . '){0,6}::' . - '|' . // contains one "::" in the middle, ending in "::WORD" - RE_IPV6_WORD . '(?::' . RE_IPV6_WORD . '){0,5}' . '::' . RE_IPV6_WORD . - '|' . // contains one "::" in the middle, not ending in "::WORD" (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. + '|' . // contains one "::" in the middle (the ^ makes the test fail if none found) + RE_IPV6_WORD . '(?::((?(-1)|:))?' . RE_IPV6_WORD . '){1,6}(?(-2)|^)' . '|' . // contains no "::" RE_IPV6_WORD . '(?::' . RE_IPV6_WORD . '){7}' . ')' - // NOTE: With PCRE 7.2+, we can combine the two '"::" in the middle' cases into: - // RE_IPV6_WORD . '(?::((?(-1)|:))?' . RE_IPV6_WORD . '){1,6}(?(-2)|^)' - // This also improves regex concatenation by using relative references. ); // An IPv6 block is an IP address and a prefix (d1 to d128) define( 'RE_IPV6_BLOCK', RE_IPV6_ADD . '\/' . RE_IPV6_PREFIX );