Skip to content

Commit b6b6ded

Browse files
External Libraries: Update the Requests library to version 2.0.6.
This is a maintenance release with minor changes: * Fix typo in deprecation notice. * Minor internal improvements for passing the correct type to function calls. * Confirmed compatibility with PHP 8.2. No changes were needed, so Requests 2.0.1 and higher can be considered compatible with PHP 8.2. * Various documentation improvements and other general housekeeping. References: * [https://github.com/WordPress/Requests/releases/tag/v2.0.6 Requests 2.0.6 release notes] * [WordPress/Requests@v2.0.5...v2.0.6 Full list of changes in Requests 2.0.6] Follow-up to [54997], [55007], [55046], [55225], [55296]. Props jrf, costdev. Fixes #58079. git-svn-id: https://develop.svn.wordpress.org/trunk@55629 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 8a6afdd commit b6b6ded

15 files changed

Lines changed: 83 additions & 49 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public static function load($class_name) {
166166
if (!defined('REQUESTS_SILENCE_PSR0_DEPRECATIONS') || REQUESTS_SILENCE_PSR0_DEPRECATIONS !== true) {
167167
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
168168
trigger_error(
169-
'The PSR-0 `Requests_...` class names in the Request library are deprecated.'
169+
'The PSR-0 `Requests_...` class names in the Requests library are deprecated.'
170170
. ' Switch to the PSR-4 `WpOrg\Requests\...` class names at your earliest convenience.',
171171
E_USER_DEPRECATED
172172
);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ interface Capability {
2828
*
2929
* Note: this does not automatically mean that the capability will be supported for your chosen transport!
3030
*
31-
* @var array<string>
31+
* @var string[]
3232
*/
3333
const ALL = [
3434
self::SSL,

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class Cookie {
3636
/**
3737
* Cookie attributes
3838
*
39-
* Valid keys are (currently) path, domain, expires, max-age, secure and
40-
* httponly.
39+
* Valid keys are `'path'`, `'domain'`, `'expires'`, `'max-age'`, `'secure'` and
40+
* `'httponly'`.
4141
*
4242
* @var \WpOrg\Requests\Utility\CaseInsensitiveDictionary|array Array-like object
4343
*/
@@ -46,8 +46,7 @@ class Cookie {
4646
/**
4747
* Cookie flags
4848
*
49-
* Valid keys are (currently) creation, last-access, persistent and
50-
* host-only.
49+
* Valid keys are `'creation'`, `'last-access'`, `'persistent'` and `'host-only'`.
5150
*
5251
* @var array
5352
*/
@@ -66,11 +65,13 @@ class Cookie {
6665
/**
6766
* Create a new cookie object
6867
*
69-
* @param string $name
70-
* @param string $value
68+
* @param string $name The name of the cookie.
69+
* @param string $value The value for the cookie.
7170
* @param array|\WpOrg\Requests\Utility\CaseInsensitiveDictionary $attributes Associative array of attribute data
72-
* @param array $flags
73-
* @param int|null $reference_time
71+
* @param array $flags The flags for the cookie.
72+
* Valid keys are `'creation'`, `'last-access'`,
73+
* `'persistent'` and `'host-only'`.
74+
* @param int|null $reference_time Reference time for relative calculations.
7475
*
7576
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $name argument is not a string.
7677
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $value argument is not a string.
@@ -279,7 +280,11 @@ public function path_matches($request_path) {
279280
public function normalize() {
280281
foreach ($this->attributes as $key => $value) {
281282
$orig_value = $value;
282-
$value = $this->normalize_attribute($key, $value);
283+
284+
if (is_string($key)) {
285+
$value = $this->normalize_attribute($key, $value);
286+
}
287+
283288
if ($value === null) {
284289
unset($this->attributes[$key]);
285290
continue;
@@ -299,7 +304,7 @@ public function normalize() {
299304
* Handles parsing individual attributes from the cookie values.
300305
*
301306
* @param string $name Attribute name
302-
* @param string|boolean $value Attribute value (string value, or true if empty/flag)
307+
* @param string|int|bool $value Attribute value (string/integer value, or true if empty/flag)
303308
* @return mixed Value if available, or null if the attribute value is invalid (and should be skipped)
304309
*/
305310
protected function normalize_attribute($name, $value) {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public function __construct($cookies = []) {
4949
/**
5050
* Normalise cookie data into a \WpOrg\Requests\Cookie
5151
*
52-
* @param string|\WpOrg\Requests\Cookie $cookie
52+
* @param string|\WpOrg\Requests\Cookie $cookie Cookie header value, possibly pre-parsed (object).
53+
* @param string $key Optional. The name for this cookie.
5354
* @return \WpOrg\Requests\Cookie
5455
*/
5556
public function normalize_cookie($cookie, $key = '') {
@@ -106,7 +107,7 @@ public function offsetSet($offset, $value) {
106107
/**
107108
* Unset the given header
108109
*
109-
* @param string $offset
110+
* @param string $offset The key for the item to unset.
110111
*/
111112
#[ReturnTypeWillChange]
112113
public function offsetUnset($offset) {
@@ -171,7 +172,7 @@ public function before_request($url, &$headers, &$data, &$type, &$options) {
171172
/**
172173
* Parse all cookies from a response and attach them to the response
173174
*
174-
* @param \WpOrg\Requests\Response $response
175+
* @param \WpOrg\Requests\Response $response Response as received.
175176
*/
176177
public function before_redirect_check(Response $response) {
177178
$url = $response->url;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public static function to_ascii($text) {
137137
*
138138
* @internal (Testing found regex was the fastest implementation)
139139
*
140-
* @param string $text
140+
* @param string $text Text to examine.
141141
* @return bool Is the text string ASCII-only?
142142
*/
143143
protected static function is_ascii($text) {
@@ -148,7 +148,7 @@ protected static function is_ascii($text) {
148148
* Prepare a text string for use as an IDNA name
149149
*
150150
* @todo Implement this based on RFC 3491 and the newer 5891
151-
* @param string $text
151+
* @param string $text Text to prepare.
152152
* @return string Prepared string
153153
*/
154154
protected static function nameprep($text) {
@@ -160,7 +160,7 @@ protected static function nameprep($text) {
160160
*
161161
* Based on \WpOrg\Requests\Iri::replace_invalid_with_pct_encoding()
162162
*
163-
* @param string $input
163+
* @param string $input Text to convert.
164164
* @return array Unicode code points
165165
*
166166
* @throws \WpOrg\Requests\Exception Invalid UTF-8 codepoint (`idna.invalidcodepoint`)
@@ -329,10 +329,10 @@ public static function punycode_encode($input) {
329329
}
330330

331331
// output the code point for digit t + ((q - t) mod (base - t))
332-
$digit = $t + (($q - $t) % (self::BOOTSTRAP_BASE - $t));
332+
$digit = (int) ($t + (($q - $t) % (self::BOOTSTRAP_BASE - $t)));
333333
$output .= self::digit_to_char($digit);
334334
// let q = (q - t) div (base - t)
335-
$q = floor(($q - $t) / (self::BOOTSTRAP_BASE - $t));
335+
$q = (int) floor(($q - $t) / (self::BOOTSTRAP_BASE - $t));
336336
} // end
337337
// output the code point for digit q
338338
$output .= self::digit_to_char($q);
@@ -381,7 +381,7 @@ protected static function digit_to_char($digit) {
381381
* @param int $delta
382382
* @param int $numpoints
383383
* @param bool $firsttime
384-
* @return int New bias
384+
* @return int|float New bias
385385
*
386386
* function adapt(delta,numpoints,firsttime):
387387
*/

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,11 @@ protected function remove_dot_segments($input) {
395395
// preceding "/" (if any) from the output buffer; otherwise,
396396
elseif (strpos($input, '/../') === 0) {
397397
$input = substr($input, 3);
398-
$output = substr_replace($output, '', strrpos($output, '/'));
398+
$output = substr_replace($output, '', (strrpos($output, '/') ?: 0));
399399
}
400400
elseif ($input === '/..') {
401401
$input = '/';
402-
$output = substr_replace($output, '', strrpos($output, '/'));
402+
$output = substr_replace($output, '', (strrpos($output, '/') ?: 0));
403403
}
404404
// D: if the input buffer consists only of "." or "..", then remove
405405
// that from the input buffer; otherwise,
@@ -824,7 +824,8 @@ protected function set_authority($authority) {
824824
else {
825825
$iuserinfo = null;
826826
}
827-
if (($port_start = strpos($remaining, ':', strpos($remaining, ']'))) !== false) {
827+
828+
if (($port_start = strpos($remaining, ':', (strpos($remaining, ']') ?: 0))) !== false) {
828829
$port = substr($remaining, $port_start + 1);
829830
if ($port === false || $port === '') {
830831
$port = null;

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class Requests {
148148
*
149149
* @var string
150150
*/
151-
const VERSION = '2.0.5';
151+
const VERSION = '2.0.6';
152152

153153
/**
154154
* Selected transport name
@@ -642,12 +642,14 @@ public static function set_certificate_path($path) {
642642
/**
643643
* Set the default values
644644
*
645+
* The $options parameter is updated with the results.
646+
*
645647
* @param string $url URL to request
646648
* @param array $headers Extra headers to send with the request
647649
* @param array|null $data Data to send either as a query string for GET/HEAD requests, or in the body for POST requests
648650
* @param string $type HTTP request type
649651
* @param array $options Options for the request
650-
* @return void $options is updated with the results
652+
* @return void
651653
*
652654
* @throws \WpOrg\Requests\Exception When the $url is not an http(s) URL.
653655
*/
@@ -824,9 +826,11 @@ protected static function parse_response($headers, $url, $req_headers, $req_data
824826
* Internal use only. Converts a raw HTTP response to a \WpOrg\Requests\Response
825827
* while still executing a multiple request.
826828
*
829+
* `$response` is either set to a \WpOrg\Requests\Response instance, or a \WpOrg\Requests\Exception object
830+
*
827831
* @param string $response Full response text including headers and body (will be overwritten with Response instance)
828832
* @param array $request Request data as passed into {@see \WpOrg\Requests\Requests::request_multiple()}
829-
* @return void `$response` is either set to a \WpOrg\Requests\Response instance, or a \WpOrg\Requests\Exception object
833+
* @return void
830834
*/
831835
public static function parse_multiple(&$response, $request) {
832836
try {

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,16 @@ public function throw_for_status($allow_redirects = true) {
137137
*
138138
* @link https://php.net/json-decode
139139
*
140-
* @param ?bool $associative Optional. When `true`, JSON objects will be returned as associative arrays;
141-
* When `false`, JSON objects will be returned as objects.
142-
* When `null`, JSON objects will be returned as associative arrays
143-
* or objects depending on whether `JSON_OBJECT_AS_ARRAY` is set in the flags.
144-
* Defaults to `true` (in contrast to the PHP native default of `null`).
145-
* @param int $depth Optional. Maximum nesting depth of the structure being decoded.
146-
* Defaults to `512`.
147-
* @param int $options Optional. Bitmask of JSON_BIGINT_AS_STRING, JSON_INVALID_UTF8_IGNORE,
148-
* JSON_INVALID_UTF8_SUBSTITUTE, JSON_OBJECT_AS_ARRAY, JSON_THROW_ON_ERROR.
149-
* Defaults to `0` (no options set).
140+
* @param bool|null $associative Optional. When `true`, JSON objects will be returned as associative arrays;
141+
* When `false`, JSON objects will be returned as objects.
142+
* When `null`, JSON objects will be returned as associative arrays
143+
* or objects depending on whether `JSON_OBJECT_AS_ARRAY` is set in the flags.
144+
* Defaults to `true` (in contrast to the PHP native default of `null`).
145+
* @param int $depth Optional. Maximum nesting depth of the structure being decoded.
146+
* Defaults to `512`.
147+
* @param int $options Optional. Bitmask of JSON_BIGINT_AS_STRING, JSON_INVALID_UTF8_IGNORE,
148+
* JSON_INVALID_UTF8_SUBSTITUTE, JSON_OBJECT_AS_ARRAY, JSON_THROW_ON_ERROR.
149+
* Defaults to `0` (no options set).
150150
*
151151
* @return array
152152
*

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Headers extends CaseInsensitiveDictionary {
2727
* Avoid using this where commas may be used unquoted in values, such as
2828
* Set-Cookie headers.
2929
*
30-
* @param string $offset
30+
* @param string $offset Name of the header to retrieve.
3131
* @return string|null Header value
3232
*/
3333
public function offsetGet($offset) {
@@ -69,7 +69,7 @@ public function offsetSet($offset, $value) {
6969
/**
7070
* Get all values for a given header
7171
*
72-
* @param string $offset
72+
* @param string $offset Name of the header to retrieve.
7373
* @return array|null Header values
7474
*
7575
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not valid as an array key.
@@ -79,7 +79,10 @@ public function getValues($offset) {
7979
throw InvalidArgument::create(1, '$offset', 'string|int', gettype($offset));
8080
}
8181

82-
$offset = strtolower($offset);
82+
if (is_string($offset)) {
83+
$offset = strtolower($offset);
84+
}
85+
8386
if (!isset($this->data[$offset])) {
8487
return null;
8588
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ private function setup_handle($url, $headers, $data, $options) {
465465
* @param string $response Response data from the body
466466
* @param array $options Request options
467467
* @return string|false HTTP response data including headers. False if non-blocking.
468-
* @throws \WpOrg\Requests\Exception
468+
* @throws \WpOrg\Requests\Exception If the request resulted in a cURL error.
469469
*/
470470
public function process_response($response, $options) {
471471
if ($options['blocking'] === false) {
@@ -561,7 +561,7 @@ public function stream_body($handle, $data) {
561561
/**
562562
* Format a URL given GET data
563563
*
564-
* @param string $url
564+
* @param string $url Original URL.
565565
* @param array|object $data Data to build query using, see {@link https://www.php.net/http_build_query}
566566
* @return string URL with data
567567
*/

0 commit comments

Comments
 (0)