@@ -67,23 +67,23 @@ class Cookie {
6767 /**
6868 * Create a new cookie object
6969 *
70- * @param string $name The name of the cookie.
70+ * @param int| string $name The name of the cookie.
7171 * @param string $value The value for the cookie.
7272 * @param array|\WpOrg\Requests\Utility\CaseInsensitiveDictionary $attributes Associative array of attribute data
7373 * @param array $flags The flags for the cookie.
7474 * Valid keys are `'creation'`, `'last-access'`,
7575 * `'persistent'` and `'host-only'`.
7676 * @param int|null $reference_time Reference time for relative calculations.
7777 *
78- * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $name argument is not a string.
78+ * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $name argument is not an integer or string that conforms to RFC 2616 .
7979 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $value argument is not a string.
8080 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $attributes argument is not an array or iterable object with array access.
8181 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $flags argument is not an array.
8282 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $reference_time argument is not an integer or null.
8383 */
8484 public function __construct ($ name , $ value , $ attributes = [], $ flags = [], $ reference_time = null ) {
85- if (is_string ($ name ) === false ) {
86- throw InvalidArgument::create (1 , '$name ' , 'string ' , gettype ($ name ));
85+ if ($ name !== '' && InputValidator:: is_valid_rfc2616_token ($ name ) === false ) {
86+ throw InvalidArgument::create (1 , '$name ' , 'integer| string and conform to RFC 2616 ' , gettype ($ name ));
8787 }
8888
8989 if (is_string ($ value ) === false ) {
@@ -102,7 +102,7 @@ public function __construct($name, $value, $attributes = [], $flags = [], $refer
102102 throw InvalidArgument::create (5 , '$reference_time ' , 'integer|null ' , gettype ($ reference_time ));
103103 }
104104
105- $ this ->name = $ name ;
105+ $ this ->name = ( string ) $ name ;
106106 $ this ->value = $ value ;
107107 $ this ->attributes = $ attributes ;
108108 $ default_flags = [
@@ -426,9 +426,9 @@ public function format_for_set_cookie() {
426426 * is an intentional deviation from RFC 2109 and RFC 2616. RFC 6265
427427 * specifies some of this handling, but not in a thorough manner.
428428 *
429- * @param string $cookie_header Cookie header value (from a Set-Cookie header)
430- * @param string $name
431- * @param int|null $reference_time
429+ * @param int| string $cookie_header Cookie header value (from a Set-Cookie header)
430+ * @param string $name
431+ * @param int|null $reference_time
432432 * @return \WpOrg\Requests\Cookie Parsed cookie object
433433 *
434434 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $cookie_header argument is not a string.
@@ -439,8 +439,12 @@ public static function parse($cookie_header, $name = '', $reference_time = null)
439439 throw InvalidArgument::create (1 , '$cookie_header ' , 'string ' , gettype ($ cookie_header ));
440440 }
441441
442- if (is_string ($ name ) === false ) {
443- throw InvalidArgument::create (2 , '$name ' , 'string ' , gettype ($ name ));
442+ if (is_string ($ name )) {
443+ $ name = trim ($ name );
444+ }
445+
446+ if ($ name !== '' && InputValidator::is_valid_rfc2616_token ($ name ) === false ) {
447+ throw InvalidArgument::create (2 , '$name ' , 'integer|string and conform to RFC 2616 ' , gettype ($ name ));
444448 }
445449
446450 $ parts = explode ('; ' , $ cookie_header );
@@ -463,6 +467,10 @@ public static function parse($cookie_header, $name = '', $reference_time = null)
463467 $ name = trim ($ name );
464468 $ value = trim ($ value );
465469
470+ if ($ name !== '' && InputValidator::is_valid_rfc2616_token ($ name ) === false ) {
471+ throw InvalidArgument::create (2 , '$name ' , 'integer|string and conform to RFC 2616 ' , gettype ($ name ));
472+ }
473+
466474 // Attribute keys are handled case-insensitively
467475 $ attributes = new CaseInsensitiveDictionary ();
468476
0 commit comments