Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 676a17e

Browse filesBrowse files
bug #23461 Use rawurlencode() to transform the Cookie into a string (javiereguiluz)
This PR was squashed before being merged into the 2.7 branch (closes #23461). Discussion ---------- Use rawurlencode() to transform the Cookie into a string | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #23255 | License | MIT | Doc PR | - Commits ------- 025dfff Use rawurlencode() to transform the Cookie into a string
2 parents 05e3332 + 025dfff commit 676a17e
Copy full SHA for 676a17e

File tree

Expand file treeCollapse file tree

4 files changed

+20
-2
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+20
-2
lines changed

‎src/Symfony/Component/BrowserKit/Cookie.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/BrowserKit/Cookie.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function __construct($name, $value, $expires = null, $path = null, $domai
6262
$this->rawValue = $value;
6363
} else {
6464
$this->value = $value;
65-
$this->rawValue = urlencode($value);
65+
$this->rawValue = rawurlencode($value);
6666
}
6767
$this->name = $name;
6868
$this->path = empty($path) ? '/' : $path;

‎src/Symfony/Component/BrowserKit/Tests/CookieTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/BrowserKit/Tests/CookieTest.php
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@
1616

1717
class CookieTest extends TestCase
1818
{
19+
public function testToString()
20+
{
21+
$cookie = new Cookie('foo', 'bar', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true);
22+
$this->assertEquals('foo=bar; expires=Fri, 20 May 2011 15:25:52 GMT; domain=.myfoodomain.com; path=/; secure; httponly', (string) $cookie, '->__toString() returns string representation of the cookie');
23+
24+
$cookie = new Cookie('foo', 'bar with white spaces', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true);
25+
$this->assertEquals('foo=bar%20with%20white%20spaces; expires=Fri, 20 May 2011 15:25:52 GMT; domain=.myfoodomain.com; path=/; secure; httponly', (string) $cookie, '->__toString() encodes the value of the cookie according to RFC 3986 (white space = %20)');
26+
27+
$cookie = new Cookie('foo', null, 1, '/admin/', '.myfoodomain.com');
28+
$this->assertEquals('foo=; expires=Thu, 01 Jan 1970 00:00:01 GMT; domain=.myfoodomain.com; path=/admin/; httponly', (string) $cookie, '->__toString() returns string representation of a cleared cookie if value is NULL');
29+
30+
$cookie = new Cookie('foo', 'bar', 0, '/', '');
31+
$this->assertEquals('foo=bar; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; httponly', (string) $cookie);
32+
}
33+
1934
/**
2035
* @dataProvider getTestsForToFromString
2136
*/

‎src/Symfony/Component/HttpFoundation/Cookie.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Cookie.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function __toString()
8282
if ('' === (string) $this->getValue()) {
8383
$str .= 'deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001);
8484
} else {
85-
$str .= urlencode($this->getValue());
85+
$str .= rawurlencode($this->getValue());
8686

8787
if (0 !== $this->getExpiresTime()) {
8888
$str .= '; expires='.gmdate('D, d-M-Y H:i:s T', $this->getExpiresTime());

‎src/Symfony/Component/HttpFoundation/Tests/CookieTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/CookieTest.php
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ public function testToString()
160160
$cookie = new Cookie('foo', 'bar', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true);
161161
$this->assertEquals('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; path=/; domain=.myfoodomain.com; secure; httponly', (string) $cookie, '->__toString() returns string representation of the cookie');
162162

163+
$cookie = new Cookie('foo', 'bar with white spaces', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true);
164+
$this->assertEquals('foo=bar%20with%20white%20spaces; expires=Fri, 20-May-2011 15:25:52 GMT; path=/; domain=.myfoodomain.com; secure; httponly', (string) $cookie, '->__toString() encodes the value of the cookie according to RFC 3986 (white space = %20)');
165+
163166
$cookie = new Cookie('foo', null, 1, '/admin/', '.myfoodomain.com');
164167
$this->assertEquals('foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; path=/admin/; domain=.myfoodomain.com; httponly', (string) $cookie, '->__toString() returns string representation of a cleared cookie if value is NULL');
165168

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.