Make WordPress Core

Changeset 38430 for trunk


Ignore:
Timestamp:
08/29/2016 02:41:56 AM (10 years ago)
Author:
dd32
Message:

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

Props swissspidy.
Fixes #37768 for trunk.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-http.php

    r38429 r38430  
    437437                        if ( $value instanceof WP_Http_Cookie ) {
    438438                                $cookie_jar[ $value->name ] = new Requests_Cookie( $value->name, $value->value, $value->get_attributes() );
    439                         } elseif ( is_string( $value ) ) {
     439                        } elseif ( is_scalar( $value ) ) {
    440440                                $cookie_jar[ $name ] = new Requests_Cookie( $name, $value );
    441441                        }
  • trunk/tests/phpunit/tests/http/http.php

    r36749 r38430  
    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.