[wp-trac] [WordPress Trac] #37437: Requests_Cookie::parse() unable to parse WP_Http_Cookie object coming from WP_Http::request()

WordPress Trac noreply at wordpress.org
Thu Jul 21 20:53:56 UTC 2016


#37437: Requests_Cookie::parse() unable to parse WP_Http_Cookie object coming from
WP_Http::request()
--------------------------+-----------------------------
 Reporter:  stephdau      |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  HTTP API      |    Version:  trunk
 Severity:  normal        |   Keywords:  needs-patch
  Focuses:                |
--------------------------+-----------------------------
 If you pass an array of cookie objects via `WP_Http::request()`'s `cookie`
 arg, which is the format it expects for cookies,
 `Requests_Cookie::parse()` will fail, as it only expects to parse strings.

 Example:
 {{{
     $response = wp_remote_get(
         'https://myawesome.site' . $path,
         array(
             'cookies' => array(
                 new WP_Http_Cookie( array( 'name' => AUTH_COOKIE, 'value'
 => wp_generate_auth_cookie( $user_id, $expiration, 'auth' ) ) ),
                 new WP_Http_Cookie( array( 'name' => SECURE_AUTH_COOKIE,
 'value' => wp_generate_auth_cookie( $user_id, $expiration, 'secure_auth' )
 ) ),
                 new WP_Http_Cookie( array( 'name' => LOGGED_IN_COOKIE,
 'value' => wp_generate_auth_cookie( $user_id, $expiration, 'logged_in' ) )
 ),
             ),
             'headers' => array(
                 'Host' => $hostname
             ),
             'sslverify' => false,
         )
     );
 }}}

 Will lead to:
 {{{
 Warning: explode() expects parameter 2 to be string, object given in
 ~/public_html/wp-includes/Requests/Cookie.php on line 383
 wp-includes/Requests/Cookie.php:383 explode(),
 wp-includes/Requests/Cookie/Jar.php:43 parse(),
 wp-includes/Requests/Cookie/Jar.php:144 normalize_cookie(),
 before_request(),
 wp-includes/Requests/Hooks.php:62 call_user_func_array(),
 wp-includes/class-requests.php:365 dispatch(),
 wp-includes/class-http.php:369 request(),
 wp-includes/class-http.php:566 request(),
 wp-includes/http.php:170 get(),
 wp_remote_get(),
 }}}

 From:
 {{{
 class Requests_Cookie {
     [...]
     public static function parse($string, $name = '', $reference_time =
 null) {
         $parts = explode(';', $string);
 }}}

 Not submitting a patch because there are many ways to handle this one,
 which should be decided.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/37437>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list