Changeset 60771 for trunk/src/wp-includes/SimplePie/src/Net/IPv6.php
- Timestamp:
- 09/16/2025 10:45:37 PM (7 months ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/SimplePie/src/Net/IPv6.php (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/SimplePie/src/Net/IPv6.php
r59141 r60771 1 1 <?php 2 2 3 /** 4 * SimplePie 5 * 6 * A PHP-Based RSS and Atom Feed Framework. 7 * Takes the hard work out of managing a complete RSS/Atom solution. 8 * 9 * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors 10 * All rights reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without modification, are 13 * permitted provided that the following conditions are met: 14 * 15 * * Redistributions of source code must retain the above copyright notice, this list of 16 * conditions and the following disclaimer. 17 * 18 * * Redistributions in binary form must reproduce the above copyright notice, this list 19 * of conditions and the following disclaimer in the documentation and/or other materials 20 * provided with the distribution. 21 * 22 * * Neither the name of the SimplePie Team nor the names of its contributors may be used 23 * to endorse or promote products derived from this software without specific prior 24 * written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS 27 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 28 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS 29 * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 33 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 * POSSIBILITY OF SUCH DAMAGE. 35 * 36 * @package SimplePie 37 * @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue 38 * @author Ryan Parman 39 * @author Sam Sneddon 40 * @author Ryan McCue 41 * @link http://simplepie.org/ SimplePie 42 * @license http://www.opensource.org/licenses/bsd-license.php BSD License 43 */ 3 // SPDX-FileCopyrightText: 2004-2023 Ryan Parman, Sam Sneddon, Ryan McCue 4 // SPDX-License-Identifier: BSD-3-Clause 5 6 declare(strict_types=1); 44 7 45 8 namespace SimplePie\Net; … … 48 11 * Class to validate and to work with IPv6 addresses. 49 12 * 50 * @package SimplePie51 * @subpackage HTTP52 13 * @copyright 2003-2005 The PHP Group 53 14 * @license http://www.opensource.org/licenses/bsd-license.php … … 63 24 * Uncompresses an IPv6 address 64 25 * 65 * RFC 4291 allows you to compress con cecutive zero pieces in an address to26 * RFC 4291 allows you to compress consecutive zero pieces in an address to 66 27 * '::'. This method expects a valid IPv6 address and expands the '::' to 67 28 * the required number of zero pieces. … … 78 39 * @return string The uncompressed IPv6 address 79 40 */ 80 public static function uncompress( $ip)41 public static function uncompress(string $ip) 81 42 { 82 43 $c1 = -1; … … 123 84 * Compresses an IPv6 address 124 85 * 125 * RFC 4291 allows you to compress con cecutive zero pieces in an address to86 * RFC 4291 allows you to compress consecutive zero pieces in an address to 126 87 * '::'. This method expects a valid IPv6 address and compresses consecutive 127 88 * zero pieces to '::'. … … 134 95 * @return string The compressed IPv6 address 135 96 */ 136 public static function compress( $ip)97 public static function compress(string $ip) 137 98 { 138 99 // Prepare the IP to be compressed … … 141 102 142 103 // Replace all leading zeros 143 $ip_parts[0] = preg_replace('/(^|:)0+([0-9])/', '\1\2', $ip_parts[0]);104 $ip_parts[0] = (string) preg_replace('/(^|:)0+([0-9])/', '\1\2', $ip_parts[0]); 144 105 145 106 // Find bunches of zeros … … 154 115 } 155 116 117 assert($pos !== null, 'For PHPStan: Since the regex matched, there is at least one match. And because the pattern is non-empty, the loop will always end with $pos ≥ 1.'); 156 118 $ip_parts[0] = substr_replace($ip_parts[0], '::', $pos, $max); 157 119 } … … 174 136 * 175 137 * @param string $ip An IPv6 address 176 * @return array [0] contains the IPv6 represented part, and [1] the IPv4 represented part177 */ 178 private static function split_v6_v4( $ip)138 * @return array{string, string} [0] contains the IPv6 represented part, and [1] the IPv4 represented part 139 */ 140 private static function split_v6_v4(string $ip): array 179 141 { 180 142 if (strpos($ip, '.') !== false) { 181 143 $pos = strrpos($ip, ':'); 144 assert($pos !== false, 'For PHPStan: IPv6 address must contain colon, since split_v6_v4 is only ever called after uncompress.'); 182 145 $ipv6_part = substr($ip, 0, $pos); 183 146 $ipv4_part = substr($ip, $pos + 1); … … 196 159 * @return bool true if $ip is a valid IPv6 address 197 160 */ 198 public static function check_ipv6( $ip)161 public static function check_ipv6(string $ip) 199 162 { 200 163 $ip = self::uncompress($ip); … … 222 185 // Check the value is valid 223 186 $value = hexdec($ipv6_part); 224 if (dechex($value) !== strtolower($ipv6_part) || $value < 0 || $value > 0xFFFF) { 187 if ($value < 0 || $value > 0xFFFF) { 188 return false; 189 } 190 assert(is_int($value), 'For PHPStan: $value is only float when $ipv6_part > PHP_INT_MAX'); 191 if (dechex($value) !== strtolower($ipv6_part)) { 225 192 return false; 226 193 } … … 249 216 * @return bool true if $ip is a valid IPv6 address 250 217 */ 251 public static function checkIPv6( $ip)218 public static function checkIPv6(string $ip) 252 219 { 253 220 return self::check_ipv6($ip);
Note: See TracChangeset
for help on using the changeset viewer.