Make WordPress Core

Changeset 38461


Ignore:
Timestamp:
08/31/2016 06:06:34 AM (8 years ago)
Author:
dd32
Message:

HTTP: Accept non-string values in cookies, fixing a regression since 4.5.

Props swissspidy.
Merges [38430] to the 4.6 branch.
Fixes #37768.

Location:
branches/4.6
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.6

  • branches/4.6/src/wp-includes/class-http.php

    r38173 r38461  
    434434            if ( $value instanceof WP_Http_Cookie ) {
    435435                $cookie_jar[ $value->name ] = new Requests_Cookie( $value->name, $value->value, $value->get_attributes() );
    436             } elseif ( is_string( $value ) ) {
     436            } elseif ( is_scalar( $value ) ) {
    437437                $cookie_jar[ $name ] = new Requests_Cookie( $name, $value );
    438438            }
  • branches/4.6/tests/phpunit/tests/http/http.php

    r36749 r38461  
    119119
    120120    }
     121
     122    /**
     123     * @ticket 37768
     124     */
     125    public function test_normalize_cookies_scalar_values() {
     126        $http = _wp_http_get_object();
     127
     128        $cookies = array(
     129            'x'   => 'foo',
     130            'y'   => 2,
     131            'z'   => 0.45,
     132            'foo' => array( 'bar' ),
     133        );
     134
     135        $cookie_jar = $http->normalize_cookies( array(
     136            'x'   => 'foo',
     137            'y'   => 2,
     138            'z'   => 0.45,
     139            'foo' => array( 'bar' ),
     140        ) );
     141
     142        $this->assertInstanceOf( 'Requests_Cookie_Jar', $cookie_jar );
     143
     144        foreach( array_keys( $cookies ) as $cookie ) {
     145            if ( 'foo' === $cookie ) {
     146                $this->assertFalse( isset( $cookie_jar[ $cookie ] ) );
     147            } else {
     148                $this->assertInstanceOf( 'Requests_Cookie', $cookie_jar[ $cookie ] );
     149            }
     150        }
     151    }
    121152}
Note: See TracChangeset for help on using the changeset viewer.