diff options
author | Aaron Schulz <aaron@users.mediawiki.org> | 2009-07-27 07:03:36 +0000 |
---|---|---|
committer | Aaron Schulz <aaron@users.mediawiki.org> | 2009-07-27 07:03:36 +0000 |
commit | 418e7767b4e6d27344bd81da8a8ddd319784f4b3 (patch) | |
tree | 4ea0bcaa5c8d839a5701a7a23fe5ada46902816c /includes/IP.php | |
parent | c0a1b76624770e5d12bc317e7ff5f6eacae2156e (diff) | |
download | mediawikicore-418e7767b4e6d27344bd81da8a8ddd319784f4b3.tar.gz mediawikicore-418e7767b4e6d27344bd81da8a8ddd319784f4b3.zip |
IPv6 padding cleanup - removed trailing ':'
Notes
Notes:
http://mediawiki.org/wiki/Special:Code/MediaWiki/53796
Diffstat (limited to 'includes/IP.php')
-rw-r--r-- | includes/IP.php | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/includes/IP.php b/includes/IP.php index 45ac6289f636..d5c61d2ff09d 100644 --- a/includes/IP.php +++ b/includes/IP.php @@ -133,11 +133,20 @@ class IP { // Remove any whitespaces, convert to upper case $ip = strtoupper( $ip ); // Expand zero abbreviations - if ( strpos( $ip, '::' ) !== false ) { - $ip = str_replace('::', str_repeat(':0', 8 - substr_count($ip, ':')) . ':', $ip); + $abbrevPos = strpos( $ip, '::' ); + if ( $abbrevPos !== false ) { + // If the '::' is at the beginning... + if( $abbrevPos == 0 ) { + $repeat = '0:'; $extra = ''; $pad = 9; // 7+2 (due to '::') + // If the '::' is at the end... + } else if( $abbrevPos == (strlen($ip)-2) ) { + $repeat = ':0'; $extra = ''; $pad = 9; // 7+2 (due to '::') + // If the '::' is at the end... + } else { + $repeat = ':0'; $extra = ':'; $pad = 8; // 6+2 (due to '::') + } + $ip = str_replace('::', str_repeat($repeat, $pad-substr_count($ip,':')).$extra, $ip); } - // For IPs that start with "::", correct the final IP so that it starts with '0' and not ':' - if ( $ip[0] == ':' ) $ip = "0$ip"; // Remove leading zereos from each bloc as needed $ip = preg_replace( '/(^|:)0+' . RE_IPV6_WORD . '/', '$1$2', $ip ); return $ip; |