Changeset 50842
- Timestamp:
- 05/11/2021 07:40:41 PM (3 years ago)
- Location:
- trunk/src/wp-includes
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/Requests/Auth.php
r46586 r50842 30 30 * @param Requests_Hooks $hooks Hook system 31 31 */ 32 public function register(Requests_Hooks &$hooks);32 public function register(Requests_Hooks $hooks); 33 33 } -
trunk/src/wp-includes/Requests/Auth/Basic.php
r46586 r50842 54 54 * @param Requests_Hooks $hooks Hook system 55 55 */ 56 public function register(Requests_Hooks &$hooks) {57 $hooks->register('curl.before_send', array( &$this, 'curl_before_send'));58 $hooks->register('fsockopen.after_headers', array( &$this, 'fsockopen_header'));56 public function register(Requests_Hooks $hooks) { 57 $hooks->register('curl.before_send', array($this, 'curl_before_send')); 58 $hooks->register('fsockopen.after_headers', array($this, 'fsockopen_header')); 59 59 } 60 60 -
trunk/src/wp-includes/Requests/Cookie.php
r46586 r50842 66 66 */ 67 67 public function __construct($name, $value, $attributes = array(), $flags = array(), $reference_time = null) { 68 $this->name = $name;69 $this->value = $value;68 $this->name = $name; 69 $this->value = $value; 70 70 $this->attributes = $attributes; 71 $default_flags = array(72 'creation' => time(),71 $default_flags = array( 72 'creation' => time(), 73 73 'last-access' => time(), 74 'persistent' => false,75 'host-only' => true,74 'persistent' => false, 75 'host-only' => true, 76 76 ); 77 $this->flags = array_merge($default_flags, $flags);77 $this->flags = array_merge($default_flags, $flags); 78 78 79 79 $this->reference_time = time(); … … 229 229 foreach ($this->attributes as $key => $value) { 230 230 $orig_value = $value; 231 $value = $this->normalize_attribute($key, $value);231 $value = $this->normalize_attribute($key, $value); 232 232 if ($value === null) { 233 233 unset($this->attributes[$key]); … … 386 386 */ 387 387 public static function parse($string, $name = '', $reference_time = null) { 388 $parts = explode(';', $string);388 $parts = explode(';', $string); 389 389 $kvparts = array_shift($parts); 390 390 … … 398 398 // 399 399 // https://bugzilla.mozilla.org/show_bug.cgi?id=169091 400 $name = '';400 $name = ''; 401 401 $value = $kvparts; 402 402 } … … 404 404 list($name, $value) = explode('=', $kvparts, 2); 405 405 } 406 $name = trim($name);406 $name = trim($name); 407 407 $value = trim($value); 408 408 … … 413 413 foreach ($parts as $part) { 414 414 if (strpos($part, '=') === false) { 415 $part_key = $part;415 $part_key = $part; 416 416 $part_value = true; 417 417 } 418 418 else { 419 419 list($part_key, $part_value) = explode('=', $part, 2); 420 $part_value = trim($part_value);421 } 422 423 $part_key = trim($part_key);420 $part_value = trim($part_value); 421 } 422 423 $part_key = trim($part_key); 424 424 $attributes[$part_key] = $part_value; 425 425 } … … 450 450 if (empty($parsed->attributes['domain']) && !empty($origin)) { 451 451 $parsed->attributes['domain'] = $origin->host; 452 $parsed->flags['host-only'] = true;452 $parsed->flags['host-only'] = true; 453 453 } 454 454 else { … … 498 498 * @codeCoverageIgnore 499 499 * @deprecated Use {@see Requests_Cookie::parse_from_headers} 500 * @return string500 * @return array 501 501 */ 502 502 public static function parseFromHeaders(Requests_Response_Headers $headers) { -
trunk/src/wp-includes/Requests/Cookie/Jar.php
r46586 r50842 69 69 * 70 70 * @param string $key Item key 71 * @return string Item value71 * @return string|null Item value (null if offsetExists is false) 72 72 */ 73 73 public function offsetGet($key) { … … 163 163 * @var Requests_Response $response 164 164 */ 165 public function before_redirect_check(Requests_Response &$return) {165 public function before_redirect_check(Requests_Response $return) { 166 166 $url = $return->url; 167 167 if (!$url instanceof Requests_IRI) { … … 169 169 } 170 170 171 $cookies = Requests_Cookie::parse_from_headers($return->headers, $url);172 $this->cookies = array_merge($this->cookies, $cookies);171 $cookies = Requests_Cookie::parse_from_headers($return->headers, $url); 172 $this->cookies = array_merge($this->cookies, $cookies); 173 173 $return->cookies = $this; 174 174 } -
trunk/src/wp-includes/Requests/Exception/Transport/cURL.php
r46586 r50842 3 3 class Requests_Exception_Transport_cURL extends Requests_Exception_Transport { 4 4 5 const EASY = 'cURLEasy';5 const EASY = 'cURLEasy'; 6 6 const MULTI = 'cURLMulti'; 7 7 const SHARE = 'cURLShare'; -
trunk/src/wp-includes/Requests/IDNAEncoder.php
r46586 r50842 142 142 $strlen = strlen($input); 143 143 144 // phpcs:ignore Generic.CodeAnalysis.JumbledIncrementer -- This is a deliberate choice. 144 145 for ($position = 0; $position < $strlen; $position++) { 145 146 $value = ord($input[$position]); … … 148 149 if ((~$value & 0x80) === 0x80) { 149 150 $character = $value; 150 $length = 1;151 $length = 1; 151 152 $remaining = 0; 152 153 } … … 154 155 elseif (($value & 0xE0) === 0xC0) { 155 156 $character = ($value & 0x1F) << 6; 156 $length = 2;157 $length = 2; 157 158 $remaining = 1; 158 159 } … … 160 161 elseif (($value & 0xF0) === 0xE0) { 161 162 $character = ($value & 0x0F) << 12; 162 $length = 3;163 $length = 3; 163 164 $remaining = 2; 164 165 } … … 166 167 elseif (($value & 0xF8) === 0xF0) { 167 168 $character = ($value & 0x07) << 18; 168 $length = 4;169 $length = 4; 169 170 $remaining = 3; 170 171 } … … 186 187 } 187 188 188 $character |= ($value & 0x3F) << (--$remaining * 6); 189 --$remaining; 190 $character |= ($value & 0x3F) << ($remaining * 6); 189 191 } 190 192 $position--; 191 193 } 192 194 193 if ( 194 // Non-shortest form sequences are invalid 195 $length > 1 && $character <= 0x7F 195 if (// Non-shortest form sequences are invalid 196 $length > 1 && $character <= 0x7F 196 197 || $length > 2 && $character <= 0x7FF 197 198 || $length > 3 && $character <= 0xFFFF … … 202 203 || ( 203 204 // Everything else not in ucschar 204 205 $character > 0xD7FF && $character < 0xF900 205 206 || $character < 0x20 206 207 || $character > 0x7E && $character < 0xA0 … … 228 229 public static function punycode_encode($input) { 229 230 $output = ''; 230 #let n = initial_n231 // let n = initial_n 231 232 $n = self::BOOTSTRAP_INITIAL_N; 232 #let delta = 0233 // let delta = 0 233 234 $delta = 0; 234 #let bias = initial_bias235 // let bias = initial_bias 235 236 $bias = self::BOOTSTRAP_INITIAL_BIAS; 236 # let h = b = the number of basic code points in the input 237 $h = $b = 0; // see loop 238 # copy them to the output in order 237 // let h = b = the number of basic code points in the input 238 $h = 0; 239 $b = 0; // see loop 240 // copy them to the output in order 239 241 $codepoints = self::utf8_to_codepoints($input); 240 $extended = array();242 $extended = array(); 241 243 242 244 foreach ($codepoints as $char) { … … 261 263 sort($extended); 262 264 $b = $h; 263 #[copy them] followed by a delimiter if b > 0265 // [copy them] followed by a delimiter if b > 0 264 266 if (strlen($output) > 0) { 265 267 $output .= '-'; 266 268 } 267 # {if the input contains a non-basic code point < n then fail} 268 # while h < length(input) do begin 269 while ($h < count($codepoints)) { 270 # let m = the minimum code point >= n in the input 269 // {if the input contains a non-basic code point < n then fail} 270 // while h < length(input) do begin 271 $codepointcount = count($codepoints); 272 while ($h < $codepointcount) { 273 // let m = the minimum code point >= n in the input 271 274 $m = array_shift($extended); 272 275 //printf('next code point to insert is %s' . PHP_EOL, dechex($m)); 273 #let delta = delta + (m - n) * (h + 1), fail on overflow276 // let delta = delta + (m - n) * (h + 1), fail on overflow 274 277 $delta += ($m - $n) * ($h + 1); 275 #let n = m278 // let n = m 276 279 $n = $m; 277 #for each code point c in the input (in order) do begin278 for ($num = 0; $num < count($codepoints); $num++) {280 // for each code point c in the input (in order) do begin 281 for ($num = 0; $num < $codepointcount; $num++) { 279 282 $c = $codepoints[$num]; 280 #if c < n then increment delta, fail on overflow283 // if c < n then increment delta, fail on overflow 281 284 if ($c < $n) { 282 285 $delta++; 283 286 } 284 #if c == n then begin287 // if c == n then begin 285 288 elseif ($c === $n) { 286 #let q = delta289 // let q = delta 287 290 $q = $delta; 288 #for k = base to infinity in steps of base do begin291 // for k = base to infinity in steps of base do begin 289 292 for ($k = self::BOOTSTRAP_BASE; ; $k += self::BOOTSTRAP_BASE) { 290 #let t = tmin if k <= bias {+ tmin}, or291 #tmax if k >= bias + tmax, or k - bias otherwise293 // let t = tmin if k <= bias {+ tmin}, or 294 // tmax if k >= bias + tmax, or k - bias otherwise 292 295 if ($k <= ($bias + self::BOOTSTRAP_TMIN)) { 293 296 $t = self::BOOTSTRAP_TMIN; … … 299 302 $t = $k - $bias; 300 303 } 301 #if q < t then break304 // if q < t then break 302 305 if ($q < $t) { 303 306 break; 304 307 } 305 #output the code point for digit t + ((q - t) mod (base - t))306 $digit = $t + (($q - $t) % (self::BOOTSTRAP_BASE - $t));308 // output the code point for digit t + ((q - t) mod (base - t)) 309 $digit = $t + (($q - $t) % (self::BOOTSTRAP_BASE - $t)); 307 310 $output .= self::digit_to_char($digit); 308 #let q = (q - t) div (base - t)311 // let q = (q - t) div (base - t) 309 312 $q = floor(($q - $t) / (self::BOOTSTRAP_BASE - $t)); 310 # end 311 } 312 # output the code point for digit q 313 } // end 314 // output the code point for digit q 313 315 $output .= self::digit_to_char($q); 314 #let bias = adapt(delta, h + 1, test h equals b?)316 // let bias = adapt(delta, h + 1, test h equals b?) 315 317 $bias = self::adapt($delta, $h + 1, $h === $b); 316 #let delta = 0318 // let delta = 0 317 319 $delta = 0; 318 #increment h320 // increment h 319 321 $h++; 320 # end 321 } 322 # end 323 } 324 # increment delta and n 322 } // end 323 } // end 324 // increment delta and n 325 325 $delta++; 326 326 $n++; 327 # end 328 } 327 } // end 329 328 330 329 return $output; … … 359 358 * @param bool $firsttime 360 359 * @return int New bias 360 * 361 * function adapt(delta,numpoints,firsttime): 361 362 */ 362 363 protected static function adapt($delta, $numpoints, $firsttime) { 363 # function adapt(delta,numpoints,firsttime): 364 # if firsttime then let delta = delta div damp 364 // if firsttime then let delta = delta div damp 365 365 if ($firsttime) { 366 366 $delta = floor($delta / self::BOOTSTRAP_DAMP); 367 367 } 368 #else let delta = delta div 2368 // else let delta = delta div 2 369 369 else { 370 370 $delta = floor($delta / 2); 371 371 } 372 #let delta = delta + (delta div numpoints)372 // let delta = delta + (delta div numpoints) 373 373 $delta += floor($delta / $numpoints); 374 #let k = 0374 // let k = 0 375 375 $k = 0; 376 #while delta > ((base - tmin) * tmax) div 2 do begin376 // while delta > ((base - tmin) * tmax) div 2 do begin 377 377 $max = floor(((self::BOOTSTRAP_BASE - self::BOOTSTRAP_TMIN) * self::BOOTSTRAP_TMAX) / 2); 378 378 while ($delta > $max) { 379 #let delta = delta div (base - tmin)379 // let delta = delta div (base - tmin) 380 380 $delta = floor($delta / (self::BOOTSTRAP_BASE - self::BOOTSTRAP_TMIN)); 381 #let k = k + base381 // let k = k + base 382 382 $k += self::BOOTSTRAP_BASE; 383 # end 384 } 385 # return k + (((base - tmin + 1) * delta) div (delta + skew)) 383 } // end 384 // return k + (((base - tmin + 1) * delta) div (delta + skew)) 386 385 return $k + floor(((self::BOOTSTRAP_BASE - self::BOOTSTRAP_TMIN + 1) * $delta) / ($delta + self::BOOTSTRAP_SKEW)); 387 386 } -
trunk/src/wp-includes/Requests/IPv6.php
r46586 r50842 41 41 42 42 list($ip1, $ip2) = explode('::', $ip); 43 $c1 = ($ip1 === '') ? -1 : substr_count($ip1, ':');44 $c2 = ($ip2 === '') ? -1 : substr_count($ip2, ':');43 $c1 = ($ip1 === '') ? -1 : substr_count($ip1, ':'); 44 $c2 = ($ip2 === '') ? -1 : substr_count($ip2, ':'); 45 45 46 46 if (strpos($ip2, '.') !== false) { … … 52 52 } 53 53 // ::xxx 54 else 54 elseif ($c1 === -1) { 55 55 $fill = str_repeat('0:', 7 - $c2); 56 $ip = str_replace('::', $fill, $ip);56 $ip = str_replace('::', $fill, $ip); 57 57 } 58 58 // xxx:: 59 else 59 elseif ($c2 === -1) { 60 60 $fill = str_repeat(':0', 7 - $c1); 61 $ip = str_replace('::', $fill, $ip);61 $ip = str_replace('::', $fill, $ip); 62 62 } 63 63 // xxx::xxx 64 64 else { 65 65 $fill = ':' . str_repeat('0:', 6 - $c2 - $c1); 66 $ip = str_replace('::', $fill, $ip);66 $ip = str_replace('::', $fill, $ip); 67 67 } 68 68 return $ip; … … 85 85 public static function compress($ip) { 86 86 // Prepare the IP to be compressed 87 $ip = self::uncompress($ip);87 $ip = self::uncompress($ip); 88 88 $ip_parts = self::split_v6_v4($ip); 89 89 … … 127 127 protected static function split_v6_v4($ip) { 128 128 if (strpos($ip, '.') !== false) { 129 $pos = strrpos($ip, ':');129 $pos = strrpos($ip, ':'); 130 130 $ipv6_part = substr($ip, 0, $pos); 131 131 $ipv4_part = substr($ip, $pos + 1); … … 146 146 */ 147 147 public static function check_ipv6($ip) { 148 $ip = self::uncompress($ip);148 $ip = self::uncompress($ip); 149 149 list($ipv6, $ipv4) = self::split_v6_v4($ip); 150 $ipv6 = explode(':', $ipv6);151 $ipv4 = explode('.', $ipv4);150 $ipv6 = explode(':', $ipv6); 151 $ipv4 = explode('.', $ipv4); 152 152 if (count($ipv6) === 8 && count($ipv4) === 1 || count($ipv6) === 6 && count($ipv4) === 4) { 153 153 foreach ($ipv6 as $ipv6_part) { -
trunk/src/wp-includes/Requests/IRI.php
r46586 r50842 68 68 * Scheme 69 69 * 70 * @var string|null 71 */ 72 protected $scheme = null; 73 74 /** 75 * User Information 76 * 77 * @var string|null 78 */ 79 protected $iuserinfo = null; 80 81 /** 82 * ihost 83 * 84 * @var string|null 85 */ 86 protected $ihost = null; 87 88 /** 89 * Port 90 * 91 * @var string|null 92 */ 93 protected $port = null; 94 95 /** 96 * ipath 97 * 70 98 * @var string 71 99 */ 72 protected $scheme = null;73 74 /**75 * User Information76 *77 * @var string78 */79 protected $iuserinfo = null;80 81 /**82 * ihost83 *84 * @var string85 */86 protected $ihost = null;87 88 /**89 * Port90 *91 * @var string92 */93 protected $port = null;94 95 /**96 * ipath97 *98 * @var string99 */100 100 protected $ipath = ''; 101 101 … … 103 103 * iquery 104 104 * 105 * @var string 105 * @var string|null 106 106 */ 107 107 protected $iquery = null; 108 108 109 109 /** 110 * ifragment 110 * ifragment|null 111 111 * 112 112 * @var string … … 119 119 * Each key is the scheme, each value is an array with each key as the IRI 120 120 * part and value as the default value for that part. 121 * 122 * @var array 121 123 */ 122 124 protected $normalization = array( … … 250 252 * Returns false if $base is not absolute, otherwise an IRI. 251 253 * 252 * @param IRI|string $base (Absolute) Base IRI253 * @param IRI|string $relative Relative IRI254 * @return IRI|false254 * @param Requests_IRI|string $base (Absolute) Base IRI 255 * @param Requests_IRI|string $relative Relative IRI 256 * @return Requests_IRI|false 255 257 */ 256 258 public static function absolutize($base, $relative) { … … 420 422 protected function replace_invalid_with_pct_encoding($string, $extra_chars, $iprivate = false) { 421 423 // Normalize as many pct-encoded sections as possible 422 $string = preg_replace_callback('/(?:%[A-Fa-f0-9]{2})+/', array( &$this, 'remove_iunreserved_percent_encoded'), $string);424 $string = preg_replace_callback('/(?:%[A-Fa-f0-9]{2})+/', array($this, 'remove_iunreserved_percent_encoded'), $string); 423 425 424 426 // Replace invalid percent characters … … 1011 1013 * Get the complete IRI 1012 1014 * 1013 * @return string 1015 * @return string|false 1014 1016 */ 1015 1017 protected function get_iri() { … … 1048 1050 * Get the complete iauthority 1049 1051 * 1050 * @return string 1052 * @return string|null 1051 1053 */ 1052 1054 protected function get_iauthority() { -
trunk/src/wp-includes/Requests/Proxy.php
r46586 r50842 32 32 * @param Requests_Hooks $hooks Hook system 33 33 */ 34 public function register(Requests_Hooks &$hooks);34 public function register(Requests_Hooks $hooks); 35 35 } -
trunk/src/wp-includes/Requests/Proxy/HTTP.php
r46586 r50842 60 60 } 61 61 elseif (is_array($args)) { 62 if (count($args) == 1) {62 if (count($args) === 1) { 63 63 list($this->proxy) = $args; 64 64 } 65 elseif (count($args) == 3) {65 elseif (count($args) === 3) { 66 66 list($this->proxy, $this->user, $this->pass) = $args; 67 $this->use_authentication = true;67 $this->use_authentication = true; 68 68 } 69 69 else { … … 83 83 * @param Requests_Hooks $hooks Hook system 84 84 */ 85 public function register(Requests_Hooks &$hooks) {86 $hooks->register('curl.before_send', array( &$this, 'curl_before_send'));85 public function register(Requests_Hooks $hooks) { 86 $hooks->register('curl.before_send', array($this, 'curl_before_send')); 87 87 88 $hooks->register('fsockopen.remote_socket', array( &$this, 'fsockopen_remote_socket'));89 $hooks->register('fsockopen.remote_host_path', array( &$this, 'fsockopen_remote_host_path'));88 $hooks->register('fsockopen.remote_socket', array($this, 'fsockopen_remote_socket')); 89 $hooks->register('fsockopen.remote_host_path', array($this, 'fsockopen_remote_host_path')); 90 90 if ($this->use_authentication) { 91 $hooks->register('fsockopen.after_headers', array( &$this, 'fsockopen_header'));91 $hooks->register('fsockopen.after_headers', array($this, 'fsockopen_header')); 92 92 } 93 93 } -
trunk/src/wp-includes/Requests/Response.php
r46586 r50842 52 52 /** 53 53 * Protocol version, false if non-blocking 54 * 54 55 * @var float|boolean 55 56 */ … … 98 99 public function is_redirect() { 99 100 $code = $this->status_code; 100 return in_array($code, array(300, 301, 302, 303, 307) ) || $code > 307 && $code < 400;101 return in_array($code, array(300, 301, 302, 303, 307), true) || $code > 307 && $code < 400; 101 102 } 102 103 -
trunk/src/wp-includes/Requests/Response/Headers.php
r46586 r50842 22 22 * 23 23 * @param string $key 24 * @return string Header value24 * @return string|null Header value 25 25 */ 26 26 public function offsetGet($key) { … … 59 59 * 60 60 * @param string $key 61 * @return array Header values61 * @return array|null Header values 62 62 */ 63 63 public function getValues($key) { -
trunk/src/wp-includes/Requests/SSL.php
r48121 r50842 21 21 * Unfortunately, PHP doesn't check the certificate against the alternative 22 22 * names, leading things like 'https://www.github.com/' to be invalid. 23 * Instead24 23 * 25 24 * @see https://tools.ietf.org/html/rfc2818#section-3.1 RFC2818, Section 3.1 … … 31 30 */ 32 31 public static function verify_certificate($host, $cert) { 33 // Calculate the valid wildcard match if the host is not an IP address34 $parts = explode('.', $host);35 if (ip2long($host) === false) {36 $parts[0] = '*';37 }38 $wildcard = implode('.', $parts);39 40 32 $has_dns_alt = false; 41 33 … … 140 132 // ruleset. 141 133 if (ip2long($host) === false) { 142 $parts = explode('.', $host);134 $parts = explode('.', $host); 143 135 $parts[0] = '*'; 144 136 $wildcard = implode('.', $parts); -
trunk/src/wp-includes/Requests/Session.php
r46586 r50842 23 23 * 24 24 * URLs will be made absolute using this as the base 25 * 25 26 * @var string|null 26 27 */ … … 29 30 /** 30 31 * Base headers for requests 32 * 31 33 * @var array 32 34 */ … … 65 67 */ 66 68 public function __construct($url = null, $headers = array(), $data = array(), $options = array()) { 67 $this->url = $url;69 $this->url = $url; 68 70 $this->headers = $headers; 69 $this->data = $data;71 $this->data = $data; 70 72 $this->options = $options; 71 73 -
trunk/src/wp-includes/Requests/Transport/cURL.php
r46586 r50842 39 39 40 40 /** 41 * Version string42 * 43 * @var long41 * cURL version number 42 * 43 * @var int 44 44 */ 45 45 public $version; … … 91 91 */ 92 92 public function __construct() { 93 $curl = curl_version();93 $curl = curl_version(); 94 94 $this->version = $curl['version_number']; 95 $this->handle = curl_init();95 $this->handle = curl_init(); 96 96 97 97 curl_setopt($this->handle, CURLOPT_HEADER, false); … … 101 101 } 102 102 if (defined('CURLOPT_PROTOCOLS')) { 103 // phpcs:ignore PHPCompatibility.Constants.NewConstants.curlopt_protocolsFound 103 104 curl_setopt($this->handle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); 104 105 } 105 106 if (defined('CURLOPT_REDIR_PROTOCOLS')) { 107 // phpcs:ignore PHPCompatibility.Constants.NewConstants.curlopt_redir_protocolsFound 106 108 curl_setopt($this->handle, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); 107 109 } … … 139 141 } 140 142 141 $this->response_data = '';142 $this->response_bytes = 0;143 $this->response_data = ''; 144 $this->response_bytes = 0; 143 145 $this->response_byte_limit = false; 144 146 if ($options['max_bytes'] !== false) { … … 169 171 curl_setopt($this->handle, CURLOPT_ENCODING, 'none'); 170 172 171 $this->response_data = '';173 $this->response_data = ''; 172 174 $this->response_bytes = 0; 173 175 curl_exec($this->handle); … … 200 202 $multihandle = curl_multi_init(); 201 203 $subrequests = array(); 202 $subhandles = array();204 $subhandles = array(); 203 205 204 206 $class = get_class($this); 205 207 foreach ($requests as $id => $request) { 206 208 $subrequests[$id] = new $class(); 207 $subhandles[$id] = $subrequests[$id]->get_subrequest_handle($request['url'], $request['headers'], $request['data'], $request['options']);209 $subhandles[$id] = $subrequests[$id]->get_subrequest_handle($request['url'], $request['headers'], $request['data'], $request['options']); 208 210 $request['options']['hooks']->dispatch('curl.before_multi_add', array(&$subhandles[$id])); 209 211 curl_multi_add_handle($multihandle, $subhandles[$id]); 210 212 } 211 213 212 $completed = 0; 213 $responses = array(); 214 $completed = 0; 215 $responses = array(); 216 $subrequestcount = count($subrequests); 214 217 215 218 $request['options']['hooks']->dispatch('curl.before_multi_exec', array(&$multihandle)); 216 219 217 220 do { 218 $active = false;221 $active = 0; 219 222 220 223 do { … … 236 239 foreach ($to_process as $key => $done) { 237 240 $options = $requests[$key]['options']; 238 if ( CURLE_OK !== $done['result']) {241 if ($done['result'] !== CURLE_OK) { 239 242 //get error string for handle. 240 $reason = curl_error($done['handle']);241 $exception = new Requests_Exception_Transport_cURL(242 243 244 245 246 243 $reason = curl_error($done['handle']); 244 $exception = new Requests_Exception_Transport_cURL( 245 $reason, 246 Requests_Exception_Transport_cURL::EASY, 247 $done['handle'], 248 $done['result'] 249 ); 247 250 $responses[$key] = $exception; 248 251 $options['hooks']->dispatch('transport.internal.parse_error', array(&$responses[$key], $requests[$key])); … … 263 266 } 264 267 } 265 while ($active || $completed < count($subrequests));268 while ($active || $completed < $subrequestcount); 266 269 267 270 $request['options']['hooks']->dispatch('curl.after_multi_exec', array(&$multihandle)); … … 288 291 } 289 292 290 $this->response_data = '';291 $this->response_bytes = 0;293 $this->response_data = ''; 294 $this->response_bytes = 0; 292 295 $this->response_byte_limit = false; 293 296 if ($options['max_bytes'] !== false) { … … 311 314 312 315 // Force closing the connection for old versions of cURL (<7.22). 313 if ( ! isset( $headers['Connection'] )) {316 if (!isset($headers['Connection'])) { 314 317 $headers['Connection'] = 'close'; 318 } 319 320 /** 321 * Add "Expect" header. 322 * 323 * By default, cURL adds a "Expect: 100-Continue" to most requests. This header can 324 * add as much as a second to the time it takes for cURL to perform a request. To 325 * prevent this, we need to set an empty "Expect" header. To match the behaviour of 326 * Guzzle, we'll add the empty header to requests that are smaller than 1 MB and use 327 * HTTP/1.1. 328 * 329 * https://curl.se/mail/lib-2017-07/0013.html 330 */ 331 if (!isset($headers['Expect']) && $options['protocol_version'] === 1.1) { 332 $headers['Expect'] = $this->get_expect_header($data); 315 333 } 316 334 … … 321 339 322 340 if ($data_format === 'query') { 323 $url = self::format_get($url, $data);341 $url = self::format_get($url, $data); 324 342 $data = ''; 325 343 } … … 364 382 } 365 383 else { 384 // phpcs:ignore PHPCompatibility.Constants.NewConstants.curlopt_timeout_msFound 366 385 curl_setopt($this->handle, CURLOPT_TIMEOUT_MS, round($timeout * 1000)); 367 386 } … … 371 390 } 372 391 else { 392 // phpcs:ignore PHPCompatibility.Constants.NewConstants.curlopt_connecttimeout_msFound 373 393 curl_setopt($this->handle, CURLOPT_CONNECTTIMEOUT_MS, round($options['connect_timeout'] * 1000)); 374 394 } … … 386 406 } 387 407 388 if ( true === $options['blocking']) {389 curl_setopt($this->handle, CURLOPT_HEADERFUNCTION, array( &$this, 'stream_headers'));390 curl_setopt($this->handle, CURLOPT_WRITEFUNCTION, array( &$this, 'stream_body'));408 if ($options['blocking'] === true) { 409 curl_setopt($this->handle, CURLOPT_HEADERFUNCTION, array($this, 'stream_headers')); 410 curl_setopt($this->handle, CURLOPT_WRITEFUNCTION, array($this, 'stream_body')); 391 411 curl_setopt($this->handle, CURLOPT_BUFFERSIZE, Requests::BUFFER_SIZE); 392 412 } … … 398 418 * @param string $response Response data from the body 399 419 * @param array $options Request options 400 * @return string HTTP response data including headers 420 * @return string|false HTTP response data including headers. False if non-blocking. 421 * @throws Requests_Exception 401 422 */ 402 423 public function process_response($response, $options) { … … 406 427 return false; 407 428 } 408 if ($options['filename'] !== false ) {429 if ($options['filename'] !== false && $this->stream_handle) { 409 430 fclose($this->stream_handle); 410 431 $this->headers = trim($this->headers); … … 440 461 // (We may want to keep this somewhere just in case) 441 462 if ($this->done_headers) { 442 $this->headers = '';463 $this->headers = ''; 443 464 $this->done_headers = false; 444 465 } … … 474 495 // Limit the length 475 496 $limited_length = ($this->response_byte_limit - $this->response_bytes); 476 $data = substr($data, 0, $limited_length);497 $data = substr($data, 0, $limited_length); 477 498 } 478 499 } … … 498 519 protected static function format_get($url, $data) { 499 520 if (!empty($data)) { 521 $query = ''; 500 522 $url_parts = parse_url($url); 501 523 if (empty($url_parts['query'])) { 502 $ query = $url_parts['query'] = '';524 $url_parts['query'] = ''; 503 525 } 504 526 else { … … 507 529 508 530 $query .= '&' . http_build_query($data, null, '&'); 509 $query = trim($query, '&');531 $query = trim($query, '&'); 510 532 511 533 if (empty($url_parts['query'])) { … … 540 562 return true; 541 563 } 564 565 /** 566 * Get the correct "Expect" header for the given request data. 567 * 568 * @param string|array $data Data to send either as the POST body, or as parameters in the URL for a GET/HEAD. 569 * @return string The "Expect" header. 570 */ 571 protected function get_expect_header($data) { 572 if (!is_array($data)) { 573 return strlen((string) $data) >= 1048576 ? '100-Continue' : ''; 574 } 575 576 $bytesize = 0; 577 $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($data)); 578 579 foreach ($iterator as $datum) { 580 $bytesize += strlen((string) $datum); 581 582 if ($bytesize >= 1048576) { 583 return '100-Continue'; 584 } 585 } 586 587 return ''; 588 } 542 589 } -
trunk/src/wp-includes/Requests/Transport/fsockopen.php
r46586 r50842 63 63 throw new Requests_Exception('Invalid URL.', 'invalidurl', $url); 64 64 } 65 $host = $url_parts['host'];66 $context = stream_context_create();67 $verifyname = false;65 $host = $url_parts['host']; 66 $context = stream_context_create(); 67 $verifyname = false; 68 68 $case_insensitive_headers = new Requests_Utility_CaseInsensitiveDictionary($headers); 69 69 … … 76 76 77 77 $context_options = array( 78 'verify_peer' => true, 79 // 'CN_match' => $host, 80 'capture_peer_cert' => true 78 'verify_peer' => true, 79 'capture_peer_cert' => true, 81 80 ); 82 $verifyname = true;81 $verifyname = true; 83 82 84 83 // SNI, if enabled (OpenSSL >=0.9.8j) 84 // phpcs:ignore PHPCompatibility.Constants.NewConstants.openssl_tlsext_server_nameFound 85 85 if (defined('OPENSSL_TLSEXT_SERVER_NAME') && OPENSSL_TLSEXT_SERVER_NAME) { 86 86 $context_options['SNI_enabled'] = true; … … 92 92 if (isset($options['verify'])) { 93 93 if ($options['verify'] === false) { 94 $context_options['verify_peer'] = false; 94 $context_options['verify_peer'] = false; 95 $context_options['verify_peer_name'] = false; 96 $verifyname = false; 95 97 } 96 98 elseif (is_string($options['verify'])) { … … 101 103 if (isset($options['verifyname']) && $options['verifyname'] === false) { 102 104 $context_options['verify_peer_name'] = false; 103 $verifyname = false;105 $verifyname = false; 104 106 } 105 107 … … 117 119 $remote_socket .= ':' . $url_parts['port']; 118 120 121 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_set_error_handler 119 122 set_error_handler(array($this, 'connect_error_handler'), E_WARNING | E_NOTICE); 120 123 … … 151 154 152 155 $request_body = ''; 153 $out = sprintf("%s %s HTTP/%.1F\r\n", $options['type'], $path, $options['protocol_version']);156 $out = sprintf("%s %s HTTP/%.1F\r\n", $options['type'], $path, $options['protocol_version']); 154 157 155 158 if ($options['type'] !== Requests::TRACE) { 156 159 if (is_array($data)) { 157 $request_body = http_build_query($data, null, '&');160 $request_body = http_build_query($data, '', '&'); 158 161 } 159 162 else { … … 161 164 } 162 165 163 if (!empty($data)) { 166 // Always include Content-length on POST requests to prevent 167 // 411 errors from some servers when the body is empty. 168 if (!empty($data) || $options['type'] === Requests::POST) { 164 169 if (!isset($case_insensitive_headers['Content-Length'])) { 165 170 $headers['Content-Length'] = strlen($request_body); … … 175 180 $out .= sprintf('Host: %s', $url_parts['host']); 176 181 177 if (( 'http' === strtolower($url_parts['scheme']) && $url_parts['port'] !== 80 ) || ( 'https' === strtolower($url_parts['scheme']) && $url_parts['port'] !== 443)) {182 if ((strtolower($url_parts['scheme']) === 'http' && $url_parts['port'] !== 80) || (strtolower($url_parts['scheme']) === 'https' && $url_parts['port'] !== 443)) { 178 183 $out .= ':' . $url_parts['port']; 179 184 } … … 221 226 222 227 $timeout_sec = (int) floor($options['timeout']); 223 if ($timeout_sec == $options['timeout']) {228 if ($timeout_sec === $options['timeout']) { 224 229 $timeout_msec = 0; 225 230 } … … 229 234 stream_set_timeout($socket, $timeout_sec, $timeout_msec); 230 235 231 $response = $body = $headers = ''; 236 $response = ''; 237 $body = ''; 238 $headers = ''; 232 239 $this->info = stream_get_meta_data($socket); 233 $size = 0;234 $doingbody = false;235 $download = false;240 $size = 0; 241 $doingbody = false; 242 $download = false; 236 243 if ($options['filename']) { 237 244 $download = fopen($options['filename'], 'wb'); … … 249 256 if (strpos($response, "\r\n\r\n")) { 250 257 list($headers, $block) = explode("\r\n\r\n", $response, 2); 251 $doingbody = true;258 $doingbody = true; 252 259 } 253 260 } … … 265 272 // Limit the length 266 273 $limited_length = ($this->max_bytes - $size); 267 $block = substr($block, 0, $limited_length);274 $block = substr($block, 0, $limited_length); 268 275 } 269 276 } … … 301 308 public function request_multiple($requests, $options) { 302 309 $responses = array(); 303 $class = get_class($this);310 $class = get_class($this); 304 311 foreach ($requests as $id => $request) { 305 312 try { 306 $handler = new $class();313 $handler = new $class(); 307 314 $responses[$id] = $handler->request($request['url'], $request['headers'], $request['data'], $request['options']); 308 315 … … 354 361 } 355 362 356 $url_parts['query'] .= '&' . http_build_query($data, null, '&');357 $url_parts['query'] = trim($url_parts['query'], '&');363 $url_parts['query'] .= '&' . http_build_query($data, '', '&'); 364 $url_parts['query'] = trim($url_parts['query'], '&'); 358 365 } 359 366 if (isset($url_parts['path'])) { -
trunk/src/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php
r46586 r50842 47 47 * 48 48 * @param string $key Item key 49 * @return string Item value49 * @return string|null Item value (null if offsetExists is false) 50 50 */ 51 51 public function offsetGet($key) { … … 71 71 } 72 72 73 $key = strtolower($key);73 $key = strtolower($key); 74 74 $this->data[$key] = $value; 75 75 } -
trunk/src/wp-includes/Requests/Utility/FilteredIterator.php
r49382 r50842 40 40 public function current() { 41 41 $value = parent::current(); 42 $value = call_user_func($this->callback, $value); 42 43 if (is_callable($this->callback)) { 44 $value = call_user_func($this->callback, $value); 45 } 46 43 47 return $value; 44 48 } … … 47 51 * @inheritdoc 48 52 */ 49 public function unserialize( $serialized ) { 50 } 53 public function unserialize($serialized) {} 51 54 52 55 /** 53 56 * @inheritdoc 57 * 58 * @phpcs:disable PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.MethodDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.NewMagicMethods.__unserializeFound 54 59 */ 55 public function __unserialize( $serialized ) { // phpcs:ignore PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.MethodDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.NewMagicMethods.__unserializeFound 56 } 60 public function __unserialize($serialized) {} 57 61 58 public function __wakeup() { // phpcs:ignore PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.MethodDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.NewMagicMethods.__wakeupFound59 unset( $this->callback);62 public function __wakeup() { 63 unset($this->callback); 60 64 } 61 65 } -
trunk/src/wp-includes/class-requests.php
r47902 r50842 89 89 * @var string 90 90 */ 91 const VERSION = '1.7 -3470169';91 const VERSION = '1.7'; 92 92 93 93 /** … … 144 144 $file = str_replace('_', '/', $class); 145 145 if (file_exists(dirname(__FILE__) . '/' . $file . '.php')) { 146 require_once (dirname(__FILE__) . '/' . $file . '.php');146 require_once dirname(__FILE__) . '/' . $file . '.php'; 147 147 } 148 148 } … … 343 343 * (string|boolean, default: library/Requests/Transport/cacert.pem) 344 344 * - `verifyname`: Should we verify the common name in the SSL certificate? 345 * (boolean : default,true)345 * (boolean, default: true) 346 346 * - `data_format`: How should we send the `$data` parameter? 347 347 * (string, one of 'query' or 'body', default: 'query' for … … 375 375 } 376 376 else { 377 $need_ssl = (0 === stripos($url, 'https://'));377 $need_ssl = (stripos($url, 'https://') === 0); 378 378 $capabilities = array('ssl' => $need_ssl); 379 $transport = self::get_transport($capabilities);379 $transport = self::get_transport($capabilities); 380 380 } 381 381 $response = $transport->request($url, $headers, $data, $options); … … 448 448 } 449 449 if (!isset($request['options'])) { 450 $request['options'] = $options;450 $request['options'] = $options; 451 451 $request['options']['type'] = $request['type']; 452 452 } … … 504 504 protected static function get_default_options($multirequest = false) { 505 505 $defaults = array( 506 'timeout' => 10,507 'connect_timeout' => 10,508 'useragent' => 'php-requests/' . self::VERSION,506 'timeout' => 10, 507 'connect_timeout' => 10, 508 'useragent' => 'php-requests/' . self::VERSION, 509 509 'protocol_version' => 1.1, 510 'redirected' => 0,511 'redirects' => 10,510 'redirected' => 0, 511 'redirects' => 10, 512 512 'follow_redirects' => true, 513 'blocking' => true,514 'type' => self::GET,515 'filename' => false,516 'auth' => false,517 'proxy' => false,518 'cookies' => false,519 'max_bytes' => false,520 'idn' => true,521 'hooks' => null,522 'transport' => null,523 'verify' => Requests::get_certificate_path(),524 'verifyname' => true,513 'blocking' => true, 514 'type' => self::GET, 515 'filename' => false, 516 'auth' => false, 517 'proxy' => false, 518 'cookies' => false, 519 'max_bytes' => false, 520 'idn' => true, 521 'hooks' => null, 522 'transport' => null, 523 'verify' => self::get_certificate_path(), 524 'verifyname' => true, 525 525 ); 526 526 if ($multirequest !== false) { … … 536 536 */ 537 537 public static function get_certificate_path() { 538 if ( ! empty( Requests::$certificate_path )) {539 return Requests::$certificate_path;538 if (!empty(self::$certificate_path)) { 539 return self::$certificate_path; 540 540 } 541 541 … … 548 548 * @param string $path Certificate path, pointing to a PEM file. 549 549 */ 550 public static function set_certificate_path( $path) {551 Requests::$certificate_path = $path;550 public static function set_certificate_path($path) { 551 self::$certificate_path = $path; 552 552 } 553 553 … … 596 596 597 597 if ($options['idn'] !== false) { 598 $iri = new Requests_IRI($url);598 $iri = new Requests_IRI($url); 599 599 $iri->host = Requests_IDNAEncoder::encode($iri->ihost); 600 $url = $iri->uri;600 $url = $iri->uri; 601 601 } 602 602 … … 605 605 606 606 if (!isset($options['data_format'])) { 607 if (in_array($type, array(self::HEAD, self::GET, self::DELETE) )) {607 if (in_array($type, array(self::HEAD, self::GET, self::DELETE), true)) { 608 608 $options['data_format'] = 'query'; 609 609 } … … 634 634 } 635 635 636 $return->raw = $headers; 637 $return->url = $url; 636 $return->raw = $headers; 637 $return->url = (string) $url; 638 $return->body = ''; 638 639 639 640 if (!$options['filename']) { 640 if (($pos = strpos($headers, "\r\n\r\n")) === false) { 641 $pos = strpos($headers, "\r\n\r\n"); 642 if ($pos === false) { 641 643 // Crap! 642 644 throw new Requests_Exception('Missing header/body separator', 'requests.no_crlf_separator'); … … 644 646 645 647 $headers = substr($return->raw, 0, $pos); 646 $return->body = substr($return->raw, $pos + strlen("\n\r\n\r")); 647 } 648 else { 649 $return->body = ''; 648 // Headers will always be separated from the body by two new lines - `\n\r\n\r`. 649 $body = substr($return->raw, $pos + 4); 650 if (!empty($body)) { 651 $return->body = $body; 652 } 650 653 } 651 654 // Pretend CRLF = LF for compatibility (RFC 2616, section 19.3) … … 659 662 } 660 663 $return->protocol_version = (float) $matches[1]; 661 $return->status_code = (int) $matches[2];664 $return->status_code = (int) $matches[2]; 662 665 if ($return->status_code >= 200 && $return->status_code < 300) { 663 666 $return->success = true; … … 666 669 foreach ($headers as $header) { 667 670 list($key, $value) = explode(':', $header, 2); 668 $value = trim($value);671 $value = trim($value); 669 672 preg_replace('#(\s+)#i', ' ', $value); 670 673 $return->headers[$key] = $value; … … 703 706 &$req_data, 704 707 &$options, 705 $return 708 $return, 706 709 ); 707 710 $options['hooks']->dispatch('requests.before_redirect', $hook_args); 708 $redirected = self::request($location, $req_headers, $req_data, $options['type'], $options);711 $redirected = self::request($location, $req_headers, $req_data, $options['type'], $options); 709 712 $redirected->history[] = $return; 710 713 return $redirected; … … 733 736 public static function parse_multiple(&$response, $request) { 734 737 try { 735 $url = $request['url'];736 $headers = $request['headers'];737 $data = $request['data'];738 $options = $request['options'];738 $url = $request['url']; 739 $headers = $request['headers']; 740 $data = $request['data']; 741 $options = $request['options']; 739 742 $response = self::parse_response($response, $url, $headers, $data, $options); 740 743 } … … 755 758 return $data; 756 759 } 757 758 759 760 760 761 $decoded = ''; … … 775 776 776 777 $chunk_length = strlen($matches[0]); 777 $decoded .= substr($encoded, $chunk_length, $length);778 $encoded = substr($encoded, $chunk_length + $length + 2);778 $decoded .= substr($encoded, $chunk_length, $length); 779 $encoded = substr($encoded, $chunk_length + $length + 2); 779 780 780 781 if (trim($encoded) === '0' || empty($encoded)) { … … 792 793 * 793 794 * @param array $array Dictionary of header values 794 * @return string[]List of headers795 * @return array List of headers 795 796 */ 796 797 public static function flatten($array) { … … 808 809 * @deprecated Misspelling of {@see Requests::flatten} 809 810 * @param array $array Dictionary of header values 810 * @return string[]List of headers811 * @return array List of headers 811 812 */ 812 813 public static function flattern($array) { … … 829 830 } 830 831 831 if (function_exists('gzdecode') && ($decoded = @gzdecode($data)) !== false) { 832 if (function_exists('gzdecode')) { 833 // phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.gzdecodeFound -- Wrapped in function_exists() for PHP 5.2. 834 $decoded = @gzdecode($data); 835 if ($decoded !== false) { 836 return $decoded; 837 } 838 } 839 840 if (function_exists('gzinflate')) { 841 $decoded = @gzinflate($data); 842 if ($decoded !== false) { 843 return $decoded; 844 } 845 } 846 847 $decoded = self::compatible_gzinflate($data); 848 if ($decoded !== false) { 832 849 return $decoded; 833 850 } 834 elseif (function_exists('gzinflate') && ($decoded = @gzinflate($data)) !== false) { 835 return $decoded; 836 } 837 elseif (($decoded = self::compatible_gzinflate($data)) !== false) { 838 return $decoded; 839 } 840 elseif (function_exists('gzuncompress') && ($decoded = @gzuncompress($data)) !== false) { 841 return $decoded; 851 852 if (function_exists('gzuncompress')) { 853 $decoded = @gzuncompress($data); 854 if ($decoded !== false) { 855 return $decoded; 856 } 842 857 } 843 858 … … 862 877 * @link https://secure.php.net/manual/en/function.gzinflate.php#77336 863 878 * 864 * @param string $gz Data String to decompress.879 * @param string $gz_data String to decompress. 865 880 * @return string|bool False on failure. 866 881 */ 867 public static function compatible_gzinflate($gz Data) {882 public static function compatible_gzinflate($gz_data) { 868 883 // Compressed data might contain a full zlib header, if so strip it for 869 884 // gzinflate() 870 if (substr($gz Data, 0, 3)== "\x1f\x8b\x08") {871 $i = 10;872 $flg = ord(substr($gz Data, 3, 1));885 if (substr($gz_data, 0, 3) === "\x1f\x8b\x08") { 886 $i = 10; 887 $flg = ord(substr($gz_data, 3, 1)); 873 888 if ($flg > 0) { 874 889 if ($flg & 4) { 875 list($xlen) = unpack('v', substr($gz Data, $i, 2));876 $i = $i +2 + $xlen;890 list($xlen) = unpack('v', substr($gz_data, $i, 2)); 891 $i += 2 + $xlen; 877 892 } 878 893 if ($flg & 8) { 879 $i = strpos($gz Data, "\0", $i) + 1;894 $i = strpos($gz_data, "\0", $i) + 1; 880 895 } 881 896 if ($flg & 16) { 882 $i = strpos($gz Data, "\0", $i) + 1;897 $i = strpos($gz_data, "\0", $i) + 1; 883 898 } 884 899 if ($flg & 2) { 885 $i = $i +2;900 $i += 2; 886 901 } 887 902 } 888 $decompressed = self::compatible_gzinflate(substr($gz Data, $i));889 if ( false !== $decompressed) {903 $decompressed = self::compatible_gzinflate(substr($gz_data, $i)); 904 if ($decompressed !== false) { 890 905 return $decompressed; 891 906 } … … 903 918 904 919 // low nibble of first byte should be 0x08 905 list(, $first_nibble) = unpack('h', $gzData);920 list(, $first_nibble) = unpack('h', $gz_data); 906 921 907 922 // First 2 bytes should be divisible by 0x1F 908 list(, $first_two_bytes) = unpack('n', $gz Data);909 910 if ( 0x08 == $first_nibble && 0 == ($first_two_bytes % 0x1F)) {923 list(, $first_two_bytes) = unpack('n', $gz_data); 924 925 if ($first_nibble === 0x08 && ($first_two_bytes % 0x1F) === 0) { 911 926 $huffman_encoded = true; 912 927 } 913 928 914 929 if ($huffman_encoded) { 915 if (false !== ($decompressed = @gzinflate(substr($gzData, 2)))) { 930 $decompressed = @gzinflate(substr($gz_data, 2)); 931 if ($decompressed !== false) { 916 932 return $decompressed; 917 933 } 918 934 } 919 935 920 if ( "\x50\x4b\x03\x04" == substr($gzData, 0, 4)) {936 if (substr($gz_data, 0, 4) === "\x50\x4b\x03\x04") { 921 937 // ZIP file format header 922 938 // Offset 6: 2 bytes, General-purpose field … … 925 941 // Offset 30: Filename field, followed by optional field, followed 926 942 // immediately by data 927 list(, $general_purpose_flag) = unpack('v', substr($gz Data, 6, 2));943 list(, $general_purpose_flag) = unpack('v', substr($gz_data, 6, 2)); 928 944 929 945 // If the file has been compressed on the fly, 0x08 bit is set of 930 946 // the general purpose field. We can use this to differentiate 931 947 // between a compressed document, and a ZIP file 932 $zip_compressed_on_the_fly = ( 0x08 == (0x08 & $general_purpose_flag));948 $zip_compressed_on_the_fly = ((0x08 & $general_purpose_flag) === 0x08); 933 949 934 950 if (!$zip_compressed_on_the_fly) { 935 951 // Don't attempt to decode a compressed zip file 936 return $gz Data;952 return $gz_data; 937 953 } 938 954 939 955 // Determine the first byte of data, based on the above ZIP header 940 956 // offsets: 941 $first_file_start = array_sum(unpack('v2', substr($gzData, 26, 4))); 942 if (false !== ($decompressed = @gzinflate(substr($gzData, 30 + $first_file_start)))) { 957 $first_file_start = array_sum(unpack('v2', substr($gz_data, 26, 4))); 958 $decompressed = @gzinflate(substr($gz_data, 30 + $first_file_start)); 959 if ($decompressed !== false) { 943 960 return $decompressed; 944 961 } … … 947 964 948 965 // Finally fall back to straight gzinflate 949 if (false !== ($decompressed = @gzinflate($gzData))) { 966 $decompressed = @gzinflate($gz_data); 967 if ($decompressed !== false) { 950 968 return $decompressed; 951 969 } … … 953 971 // Fallback for all above failing, not expected, but included for 954 972 // debugging and preventing regressions and to track stats 955 if (false !== ($decompressed = @gzinflate(substr($gzData, 2)))) { 973 $decompressed = @gzinflate(substr($gz_data, 2)); 974 if ($decompressed !== false) { 956 975 return $decompressed; 957 976 }
Note: See TracChangeset
for help on using the changeset viewer.