HTTP: Accept non-string values in cookies, fixing a regression since 4.5.
Props swissspidy. Fixes #37768 for trunk. git-svn-id: https://develop.svn.wordpress.org/trunk@38430 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
7f2a81061a
commit
e916b9e14c
@ -436,7 +436,7 @@ class WP_Http {
|
|||||||
foreach ( $cookies as $name => $value ) {
|
foreach ( $cookies as $name => $value ) {
|
||||||
if ( $value instanceof WP_Http_Cookie ) {
|
if ( $value instanceof WP_Http_Cookie ) {
|
||||||
$cookie_jar[ $value->name ] = new Requests_Cookie( $value->name, $value->value, $value->get_attributes() );
|
$cookie_jar[ $value->name ] = new Requests_Cookie( $value->name, $value->value, $value->get_attributes() );
|
||||||
} elseif ( is_string( $value ) ) {
|
} elseif ( is_scalar( $value ) ) {
|
||||||
$cookie_jar[ $name ] = new Requests_Cookie( $name, $value );
|
$cookie_jar[ $name ] = new Requests_Cookie( $name, $value );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,4 +118,35 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase {
|
|||||||
$this->assertEquals( array_keys( $wp_header_to_desc ), array_values( $constants ) );
|
$this->assertEquals( array_keys( $wp_header_to_desc ), array_values( $constants ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 37768
|
||||||
|
*/
|
||||||
|
public function test_normalize_cookies_scalar_values() {
|
||||||
|
$http = _wp_http_get_object();
|
||||||
|
|
||||||
|
$cookies = array(
|
||||||
|
'x' => 'foo',
|
||||||
|
'y' => 2,
|
||||||
|
'z' => 0.45,
|
||||||
|
'foo' => array( 'bar' ),
|
||||||
|
);
|
||||||
|
|
||||||
|
$cookie_jar = $http->normalize_cookies( array(
|
||||||
|
'x' => 'foo',
|
||||||
|
'y' => 2,
|
||||||
|
'z' => 0.45,
|
||||||
|
'foo' => array( 'bar' ),
|
||||||
|
) );
|
||||||
|
|
||||||
|
$this->assertInstanceOf( 'Requests_Cookie_Jar', $cookie_jar );
|
||||||
|
|
||||||
|
foreach( array_keys( $cookies ) as $cookie ) {
|
||||||
|
if ( 'foo' === $cookie ) {
|
||||||
|
$this->assertFalse( isset( $cookie_jar[ $cookie ] ) );
|
||||||
|
} else {
|
||||||
|
$this->assertInstanceOf( 'Requests_Cookie', $cookie_jar[ $cookie ] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user