You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* @param string|null $value The value of the cookie
72
78
* @param int|string|\DateTimeInterface $expire The time the cookie expires
73
79
* @param string $path The path on the server in which the cookie will be available on
74
80
* @param string|null $domain The domain that the cookie is available to
75
-
* @param bool $secure Whether the cookie should only be transmitted over a secure HTTPS connection from the client
81
+
* @param bool|null$secureWhether the client should send back the cookie only over HTTPS or null to auto-enable this when the request is already using HTTPS
76
82
* @param bool $httpOnly Whether the cookie will be made accessible only through the HTTP protocol
77
83
* @param bool $raw Whether the cookie value should be sent with no url encoding
78
84
* @param string|null $sameSite Whether the cookie will be available for cross-site requests
@trigger_error(sprintf('The default value of the "$secure" and "$samesite" arguments of "%s"\'s constructor will respectively change from "false" to "null" and from "null" to "lax" in Symfony 5.0, you should define their values explicitly or use "Cookie::create()" instead.', __METHOD__), E_USER_DEPRECATED);
92
+
}
93
+
84
94
// from PHP source code
85
95
if (preg_match("/[=,; \t\r\n\013\014]/", $name)) {
86
96
thrownew \InvalidArgumentException(sprintf('The cookie name "%s" contains invalid characters.', $name));
@@ -110,7 +120,9 @@ public function __construct(string $name, string $value = null, $expire = 0, ?st
110
120
$this->httpOnly = $httpOnly;
111
121
$this->raw = $raw;
112
122
113
-
if (null !== $sameSite) {
123
+
if ('' === $sameSite) {
124
+
$sameSite = null;
125
+
} elseif (null !== $sameSite) {
114
126
$sameSite = strtolower($sameSite);
115
127
}
116
128
@@ -232,7 +244,7 @@ public function getPath()
232
244
*/
233
245
publicfunctionisSecure()
234
246
{
235
-
return$this->secure;
247
+
return$this->secure ?? $this->secureDefault;
236
248
}
237
249
238
250
/**
@@ -274,4 +286,12 @@ public function getSameSite()
274
286
{
275
287
return$this->sameSite;
276
288
}
289
+
290
+
/**
291
+
* @param bool $default The default value of the "secure" flag when it is set to null
$this->assertEquals('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; Max-Age=0; path=/; domain=.myfoodomain.com; secure; httponly', (string) $cookie, '->__toString() returns string representation of the cookie');
175
175
176
-
$cookie = newCookie('foo', 'bar with white spaces', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true);
176
+
$cookie = Cookie::create('foo', 'bar with white spaces', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true, true, false, null);
177
177
$this->assertEquals('foo=bar%20with%20white%20spaces; expires=Fri, 20-May-2011 15:25:52 GMT; Max-Age=0; path=/; domain=.myfoodomain.com; secure; httponly', (string) $cookie, '->__toString() encodes the value of the cookie according to RFC 3986 (white space = %20)');
0 commit comments