Skip to content

Commit 2b4b7f6

Browse files
committed
External Libraries: Update Requests library to version 2.0.21.
This update primarily includes a PHP 8.6 compatibility fix. The only other changes found in 2.0.18-2.0.21 are to the root certificate bundle included in the library, which are skipped as WordPress manages its own certificate bundle. Props davidbaumwald. Fixes #66647. git-svn-id: https://develop.svn.wordpress.org/trunk@65383 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 260ddc4 commit 2b4b7f6

10 files changed

Lines changed: 44 additions & 34 deletions

File tree

‎src/wp-includes/Requests/src/Cookie.php‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use WpOrg\Requests\Response\Headers;
1313
use WpOrg\Requests\Utility\CaseInsensitiveDictionary;
1414
use WpOrg\Requests\Utility\InputValidator;
15+
use WpOrg\Requests\Utility\Trim;
1516

1617
/**
1718
* Cookie storage object
@@ -439,8 +440,8 @@ public static function parse($cookie_header, $name = '', $reference_time = null)
439440
list($name, $value) = explode('=', $kvparts, 2);
440441
}
441442

442-
$name = trim($name);
443-
$value = trim($value);
443+
$name = trim($name, Trim::WHITESPACE_CHARS_NO_FF);
444+
$value = trim($value, Trim::WHITESPACE_CHARS_NO_FF);
444445

445446
// Attribute keys are handled case-insensitively
446447
$attributes = new CaseInsensitiveDictionary();
@@ -452,10 +453,10 @@ public static function parse($cookie_header, $name = '', $reference_time = null)
452453
$part_value = true;
453454
} else {
454455
list($part_key, $part_value) = explode('=', $part, 2);
455-
$part_value = trim($part_value);
456+
$part_value = trim($part_value, Trim::WHITESPACE_CHARS_NO_FF);
456457
}
457458

458-
$part_key = trim($part_key);
459+
$part_key = trim($part_key, Trim::WHITESPACE_CHARS_NO_FF);
459460
$attributes[$part_key] = $part_value;
460461
}
461462
}

‎src/wp-includes/Requests/src/Exception/Transport/Curl.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,4 @@ public function __construct($message, $type, $data = null, $code = 0) {
7676
public function getReason() {
7777
return $this->reason;
7878
}
79-
8079
}

‎src/wp-includes/Requests/src/IdnaEncoder.php‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ protected static function utf8_to_codepoints($input) {
212212
$character |= ($value & 0x3F) << ($remaining * 6);
213213
}
214214

215-
$position--;
215+
--$position;
216216
}
217217

218218
if (// Non-shortest form sequences are invalid
@@ -270,7 +270,7 @@ public static function punycode_encode($input) {
270270
// Character is valid ASCII
271271
// TODO: this should also check if it's valid for a URL
272272
$output .= chr($char);
273-
$h++;
273+
++$h;
274274

275275
// Check if the character is non-ASCII, but below initial n
276276
// This never occurs for Punycode, so ignore in coverage
@@ -307,7 +307,7 @@ public static function punycode_encode($input) {
307307
$c = $codepoints[$num];
308308
// if c < n then increment delta, fail on overflow
309309
if ($c < $n) {
310-
$delta++;
310+
++$delta;
311311
} elseif ($c === $n) { // if c == n then begin
312312
// let q = delta
313313
$q = $delta;
@@ -341,12 +341,12 @@ public static function punycode_encode($input) {
341341
// let delta = 0
342342
$delta = 0;
343343
// increment h
344-
$h++;
344+
++$h;
345345
} // end
346346
} // end
347347
// increment delta and n
348-
$delta++;
349-
$n++;
348+
++$delta;
349+
++$n;
350350
} // end
351351

352352
return $output;

‎src/wp-includes/Requests/src/Ipv6.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static function uncompress($ip) {
5656
$c2 = ($ip2 === '') ? -1 : substr_count($ip2, ':');
5757

5858
if (strpos($ip2, '.') !== false) {
59-
$c2++;
59+
++$c2;
6060
}
6161

6262
if ($c1 === -1 && $c2 === -1) {

‎src/wp-includes/Requests/src/Requests.php‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use WpOrg\Requests\Transport\Curl;
2525
use WpOrg\Requests\Transport\Fsockopen;
2626
use WpOrg\Requests\Utility\InputValidator;
27+
use WpOrg\Requests\Utility\Trim;
2728

2829
/**
2930
* Requests for PHP
@@ -35,6 +36,13 @@
3536
* @package Requests
3637
*/
3738
class Requests {
39+
/**
40+
* Current version of Requests
41+
*
42+
* @var string
43+
*/
44+
const VERSION = '2.0.21';
45+
3846
/**
3947
* POST method
4048
*
@@ -143,13 +151,6 @@ class Requests {
143151
Fsockopen::class => Fsockopen::class,
144152
];
145153

146-
/**
147-
* Current version of Requests
148-
*
149-
* @var string
150-
*/
151-
const VERSION = '2.0.17';
152-
153154
/**
154155
* Selected transport name
155156
*
@@ -763,7 +764,7 @@ protected static function parse_response($headers, $url, $req_headers, $req_data
763764

764765
foreach ($headers as $header) {
765766
list($key, $value) = explode(':', $header, 2);
766-
$value = trim($value);
767+
$value = trim($value, Trim::WHITESPACE_CHARS_NO_FF);
767768
preg_replace('#(\s+)#i', ' ', $value);
768769
$return->headers[$key] = $value;
769770
}
@@ -790,7 +791,7 @@ protected static function parse_response($headers, $url, $req_headers, $req_data
790791
$options['type'] = self::GET;
791792
}
792793

793-
$options['redirected']++;
794+
++$options['redirected'];
794795
$location = $return->headers['location'];
795796
if (strpos($location, 'http://') !== 0 && strpos($location, 'https://') !== 0) {
796797
// relative redirect, for compatibility make it absolute
@@ -852,7 +853,7 @@ public static function parse_multiple(&$response, $request) {
852853
* @return string Decoded body
853854
*/
854855
protected static function decode_chunked($data) {
855-
if (!preg_match('/^([0-9a-f]+)(?:;(?:[\w-]*)(?:=(?:(?:[\w-]*)*|"(?:[^\r\n])*"))?)*\r\n/i', trim($data))) {
856+
if (!preg_match('/^([0-9a-f]+)(?:;(?:[\w-]*)(?:=(?:(?:[\w-]*)*|"(?:[^\r\n])*"))?)*\r\n/i', trim($data, Trim::WHITESPACE_CHARS_NO_FF))) {
856857
return $data;
857858
}
858859

@@ -866,7 +867,7 @@ protected static function decode_chunked($data) {
866867
return $data;
867868
}
868869

869-
$length = hexdec(trim($matches[1]));
870+
$length = hexdec(trim($matches[1], Trim::WHITESPACE_CHARS_NO_FF));
870871
if ($length === 0) {
871872
// Ignore trailer headers
872873
return $decoded;
@@ -876,7 +877,7 @@ protected static function decode_chunked($data) {
876877
$decoded .= substr($encoded, $chunk_length, $length);
877878
$encoded = substr($encoded, $chunk_length + $length + 2);
878879

879-
if (trim($encoded) === '0' || empty($encoded)) {
880+
if (trim($encoded, Trim::WHITESPACE_CHARS_NO_FF) === '0' || empty($encoded)) {
880881
return $decoded;
881882
}
882883
}
@@ -923,7 +924,7 @@ public static function decompress($data) {
923924
throw InvalidArgument::create(1, '$data', 'string', gettype($data));
924925
}
925926

926-
if (trim($data) === '') {
927+
if (trim($data, Trim::WHITESPACE_CHARS_NO_FF) === '') {
927928
// Empty body does not need further processing.
928929
return $data;
929930
}
@@ -990,7 +991,7 @@ public static function compatible_gzinflate($gz_data) {
990991
throw InvalidArgument::create(1, '$gz_data', 'string', gettype($gz_data));
991992
}
992993

993-
if (trim($gz_data) === '') {
994+
if (trim($gz_data, Trim::WHITESPACE_CHARS_NO_FF) === '') {
994995
return false;
995996
}
996997

‎src/wp-includes/Requests/src/Response.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function __construct() {
108108
*/
109109
public function is_redirect() {
110110
$code = $this->status_code;
111-
return in_array($code, [300, 301, 302, 303, 307], true) || $code > 307 && $code < 400;
111+
return in_array($code, [300, 301, 302, 303, 307], true) || ($code > 307 && $code < 400);
112112
}
113113

114114
/**

‎src/wp-includes/Requests/src/Session.php‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,13 @@ public function patch($url, $headers, $data = [], $options = []) {
227227
* @throws \WpOrg\Requests\Exception On invalid URLs (`nonhttp`)
228228
*/
229229
public function request($url, $headers = [], $data = [], $type = Requests::GET, $options = []) {
230-
$request = $this->merge_request(compact('url', 'headers', 'data', 'options'));
230+
$request = [
231+
'url' => $url,
232+
'headers' => $headers,
233+
'data' => $data,
234+
'options' => $options,
235+
];
236+
$request = $this->merge_request($request);
231237

232238
return Requests::request($request['url'], $request['headers'], $request['data'], $type, $request['options']);
233239
}

‎src/wp-includes/Requests/src/Ssl.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use WpOrg\Requests\Exception\InvalidArgument;
1111
use WpOrg\Requests\Utility\InputValidator;
12+
use WpOrg\Requests\Utility\Trim;
1213

1314
/**
1415
* SSL utilities for Requests
@@ -47,15 +48,15 @@ public static function verify_certificate($host, $cert) {
4748
if (!empty($cert['extensions']['subjectAltName'])) {
4849
$altnames = explode(',', $cert['extensions']['subjectAltName']);
4950
foreach ($altnames as $altname) {
50-
$altname = trim($altname);
51+
$altname = trim($altname, Trim::WHITESPACE_CHARS_NO_FF);
5152
if (strpos($altname, 'DNS:') !== 0) {
5253
continue;
5354
}
5455

5556
$has_dns_alt = true;
5657

5758
// Strip the 'DNS:' prefix and trim whitespace
58-
$altname = trim(substr($altname, 4));
59+
$altname = trim(substr($altname, 4), Trim::WHITESPACE_CHARS_NO_FF);
5960

6061
// Check for a match
6162
if (self::match_domain($host, $altname) === true) {

‎src/wp-includes/Requests/src/Transport/Curl.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use WpOrg\Requests\Requests;
1717
use WpOrg\Requests\Transport;
1818
use WpOrg\Requests\Utility\InputValidator;
19+
use WpOrg\Requests\Utility\Trim;
1920

2021
/**
2122
* cURL HTTP transport
@@ -316,7 +317,7 @@ public function request_multiple($requests, $options) {
316317
$options['hooks']->dispatch('multiple.request.complete', [&$responses[$key], $key]);
317318
}
318319

319-
$completed++;
320+
++$completed;
320321
}
321322
} while ($active || $completed < $subrequestcount);
322323

@@ -480,7 +481,7 @@ public function process_response($response, $options) {
480481

481482
if ($options['filename'] !== false && $this->stream_handle) {
482483
fclose($this->stream_handle);
483-
$this->headers = trim($this->headers);
484+
$this->headers = trim($this->headers, Trim::WHITESPACE_CHARS_NO_FF);
484485
} else {
485486
$this->headers .= $response;
486487
}

‎src/wp-includes/Requests/src/Transport/Fsockopen.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use WpOrg\Requests\Transport;
1717
use WpOrg\Requests\Utility\CaseInsensitiveDictionary;
1818
use WpOrg\Requests\Utility\InputValidator;
19+
use WpOrg\Requests\Utility\Trim;
1920

2021
/**
2122
* fsockopen HTTP transport
@@ -183,7 +184,7 @@ public function request($url, $headers = [], $data = [], $options = []) {
183184
if (!$socket) {
184185
if ($errno === 0) {
185186
// Connection issue
186-
throw new Exception(rtrim($this->connect_error), 'fsockopen.connect_error');
187+
throw new Exception(rtrim($this->connect_error, Trim::WHITESPACE_CHARS), 'fsockopen.connect_error');
187188
}
188189

189190
throw new Exception($errstr, 'fsockopenerror', null, $errno);
@@ -486,7 +487,7 @@ public function verify_certificate_from_context($host, $context) {
486487
// If we don't have SSL options, then we couldn't make the connection at
487488
// all
488489
if (empty($meta) || empty($meta['ssl']) || empty($meta['ssl']['peer_certificate'])) {
489-
throw new Exception(rtrim($this->connect_error), 'ssl.connect_error');
490+
throw new Exception(rtrim($this->connect_error, Trim::WHITESPACE_CHARS), 'ssl.connect_error');
490491
}
491492

492493
$cert = openssl_x509_parse($meta['ssl']['peer_certificate']);

0 commit comments

Comments
 (0)