Make WordPress Core

Changeset 55629


Ignore:
Timestamp:
04/05/2023 01:10:53 PM (18 months ago)
Author:
SergeyBiryukov
Message:

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:

Follow-up to [54997], [55007], [55046], [55225], [55296].

Props jrf, costdev.
Fixes #58079.

Location:
trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/Requests/src/Autoload.php

    r54997 r55629  
    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
  • trunk/src/wp-includes/Requests/src/Capability.php

    r54997 r55629  
    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 = [
  • trunk/src/wp-includes/Requests/src/Cookie.php

    r54997 r55629  
    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
     
    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
     
    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.
     
    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]);
     
    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     */
  • trunk/src/wp-includes/Requests/src/Cookie/Jar.php

    r54997 r55629  
    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     */
     
    107108     * Unset the given header
    108109     *
    109      * @param string $offset
     110     * @param string $offset The key for the item to unset.
    110111     */
    111112    #[ReturnTypeWillChange]
     
    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) {
  • trunk/src/wp-includes/Requests/src/IdnaEncoder.php

    r54997 r55629  
    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     */
     
    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     */
     
    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     *
     
    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
     
    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):
  • trunk/src/wp-includes/Requests/src/Iri.php

    r54997 r55629  
    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
     
    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 === '') {
  • trunk/src/wp-includes/Requests/src/Requests.php

    r54997 r55629  
    149149     * @var string
    150150     */
    151     const VERSION = '2.0.5';
     151    const VERSION = '2.0.6';
    152152
    153153    /**
     
    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
     
    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.
     
    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) {
  • trunk/src/wp-includes/Requests/src/Response.php

    r54997 r55629  
    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
  • trunk/src/wp-includes/Requests/src/Response/Headers.php

    r54997 r55629  
    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     */
     
    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     *
     
    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;
  • trunk/src/wp-includes/Requests/src/Transport/Curl.php

    r54997 r55629  
    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) {
     
    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
  • trunk/src/wp-includes/Requests/src/Transport/Fsockopen.php

    r54997 r55629  
    5252    private $max_bytes = false;
    5353
     54    /**
     55     * Cache for received connection errors.
     56     *
     57     * @var string
     58     */
    5459    private $connect_error = '';
    5560
     
    406411     * Format a URL given GET data
    407412     *
    408      * @param array $url_parts
     413     * @param array        $url_parts Array of URL parts as received from {@link https://www.php.net/parse_url}
    409414     * @param array|object $data Data to build query using, see {@link https://www.php.net/http_build_query}
    410415     * @return string URL with data
  • trunk/src/wp-includes/Requests/src/Utility/CaseInsensitiveDictionary.php

    r54997 r55629  
    9696     * Unset the given header
    9797     *
    98      * @param string $offset
     98     * @param string $offset The key for the item to unset.
    9999     */
    100100    #[ReturnTypeWillChange]
  • trunk/src/wp-includes/Requests/src/Utility/FilteredIterator.php

    r54997 r55629  
    2929     * Create a new iterator
    3030     *
    31      * @param array $data
     31     * @param array    $data     The array or object to be iterated on.
    3232     * @param callable $callback Callback to be called on each value
    3333     *
     
    4747
    4848    /**
    49      * @inheritdoc
     49     * Prevent unserialization of the object for security reasons.
    5050     *
    5151     * @phpcs:disable PHPCompatibility.FunctionNameRestrictions.NewMagicMethods.__unserializeFound
     52     *
     53     * @param array $data Restored array of data originally serialized.
     54     *
     55     * @return void
    5256     */
    5357    #[ReturnTypeWillChange]
     
    5559    // phpcs:enable
    5660
     61    /**
     62     * Perform reinitialization tasks.
     63     *
     64     * Prevents a callback from being injected during unserialization of an object.
     65     *
     66     * @return void
     67     */
    5768    public function __wakeup() {
    5869        unset($this->callback);
     
    7687
    7788    /**
    78      * @inheritdoc
     89     * Prevent creating a PHP value from a stored representation of the object for security reasons.
     90     *
     91     * @param string $data The serialized string.
     92     *
     93     * @return void
    7994     */
    8095    #[ReturnTypeWillChange]
  • trunk/src/wp-includes/class-requests.php

    r54997 r55629  
    2020    // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
    2121    trigger_error(
    22         'The PSR-0 `Requests_...` class names in the Request library are deprecated.'
     22        'The PSR-0 `Requests_...` class names in the Requests library are deprecated.'
    2323        . ' Switch to the PSR-4 `WpOrg\Requests\...` class names at your earliest convenience.',
    2424        E_USER_DEPRECATED
  • trunk/tests/phpunit/tests/http/includeOldRequestsClass.php

    r55007 r55629  
    1616    public function test_should_include_old_requests_class() {
    1717        $this->expectDeprecation();
    18         $this->expectDeprecationMessage( 'The PSR-0 `Requests_...` class names in the Request library are deprecated.' );
     18        $this->expectDeprecationMessage( 'The PSR-0 `Requests_...` class names in the Requests library are deprecated.' );
    1919
    2020        new Requests();
Note: See TracChangeset for help on using the changeset viewer.