diff --git a/src/wp-includes/class-http.php b/src/wp-includes/class-http.php index 2fd4c54ea6..c7a09cfc40 100644 --- a/src/wp-includes/class-http.php +++ b/src/wp-includes/class-http.php @@ -436,7 +436,7 @@ class WP_Http { foreach ( $cookies as $name => $value ) { if ( $value instanceof WP_Http_Cookie ) { $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 ); } } diff --git a/tests/phpunit/tests/http/http.php b/tests/phpunit/tests/http/http.php index 74eda29e21..ed0b9eeefb 100644 --- a/tests/phpunit/tests/http/http.php +++ b/tests/phpunit/tests/http/http.php @@ -118,4 +118,35 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { $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 ] ); + } + } + } }