8000 merged branch TrackIF/master (PR #7149) · symfony/symfony@0fb397c · GitHub
[go: up one dir, main page]

Skip to content

Commit 0fb397c

Browse files
committed
merged branch TrackIF/master (PR #7149)
This PR was submitted for the master branch but it was merged into the 2.1 branch instead (closes #7149). Commits ------- 0c25d41 Expanded fault-tolerance for unusual cookie dates Discussion ---------- Expanded fault-tolerance for unusual cookie dates Building on pull #1793, this resolves situations where the Cookie's date field uses a numeric month. Also, expanding on the 7 most typical formats we fall-back to date_create() before throwing an exception. --------------------------------------------------------------------------- by vicb at 2013-02-21T17:30:28Z Please add some unit tests for the new formats. --------------------------------------------------------------------------- by ecaron at 2013-02-21T18:06:46Z Sorry for neglecting the unit tests, they've been updated (2 matching new common date formats, 1 uncommon date format, and changing the existing bad-date check to be more realistically bad.) I also changed from strtotime to date_create to match the existing DateTime::createFromFormat check (although in my cookiejar analysis leading to this pull requests, all the cookies I'd encountered had timezones in them.) I'm using date_create vs. constructing a DateTime so I can immediately rely on the return value. --------------------------------------------------------------------------- by ecaron at 2013-02-21T18:21:03Z @vicb The two Travis failures are against the master branch unrelated to my changes. Should I retarget this pull against 2.3, or what would you advise to get this pull accepted? --------------------------------------------------------------------------- by vicb at 2013-02-21T19:40:59Z The Travis failure come for a bug in PHPUnit (there is a Sf issue for that). There is no 2.3 branch yet (devs happen in master). @fabpot will decide wether this should be considered a a fix (and merge to former releases) or an enhancement which will be merged to 2.3. _(Could you please update the PR header which still refers to strtotime, thanks)_ --------------------------------------------------------------------------- by fabpot at 2013-02-21T21:37:15Z This should probably go into 2.0. Also, do you have a reference where those 7 formats are explained/described? --------------------------------------------------------------------------- by ecaron at 2013-02-21T23:10:38Z @fabpot I couldn't find a reference because the cookies that we're addressing are ones that are behaving outside the spec (at least what I understand from http://curl.haxx.se/rfc/cookie_spec.html), as pull #1793 began to address and this continues. The cases that I've added are ones that I have encountered over the weeks of using BrowserKit and Goutte.
2 parents 9f59ac9 + 368f62f commit 0fb397c

File tree

2 files changed

+11
-1
lines changed
  • src/Symfony/Component/BrowserKit

2 files changed

+11
-1
lines changed

src/Symfony/Component/BrowserKit/Cookie.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class Cookie
3030
'D, d M Y H:i:s T',
3131
'D, d-M-y H:i:s T',
3232
'D, d-M-Y H:i:s T',
33+
'D, d-m-y H:i:s T',
34+
'D, d-m-Y H:i:s T',
3335
'D M j G:i:s Y',
3436
'D M d H:i:s Y T',
3537
);
@@ -203,6 +205,11 @@ private static function parseDate($dateValue)
203205
}
204206
}
205207

208+
// attempt a fallback for unusual formatting
209+
if (false !== $date = date_create($dateValue, new \DateTimeZone('GMT'))) {
210+
return $date->getTimestamp();
211+
}
212+
206213
throw new \InvalidArgumentException(sprintf('Could not parse date "%s".', $dateValue));
207214
}
208215

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ public function getExpireCookieStrings()
5656
return array(
5757
array('foo=bar; expires=Fri, 31-Jul-2020 08:49:37 GMT'),
5858
array('foo=bar; expires=Fri, 31 Jul 2020 08:49:37 GMT'),
59+
array('foo=bar; expires=Fri, 31-07-2020 08:49:37 GMT'),
60+ array('foo=bar; expires=Fri, 31-07-20 08:49:37 GMT'),
5961
array('foo=bar; expires=Friday, 31-Jul-20 08:49:37 GMT'),
6062
array('foo=bar; expires=Fri Jul 31 08:49:37 2020'),
6163
array('foo=bar; expires=\'Fri Jul 31 08:49:37 2020\''),
64+
array('foo=bar; expires=Friday July 31st 2020, 08:49:37 GMT'),
6265
);
6366
}
6467

@@ -86,7 +89,7 @@ public function testFromStringThrowsAnExceptionIfCookieIsNotValid()
8689
public function testFromStringThrowsAnExceptionIfCookieDateIsNotValid()
8790
{
8891
$this->setExpectedException('InvalidArgumentException');
89-
Cookie::FromString('foo=bar; expires=foo');
92+
Cookie::FromString('foo=bar; expires=Flursday July 31st 2020, 08:49:37 GMT');
9093
}
9194

9295
public function testFromStringThrowsAnExceptionIfUrlIsNotValid()

0 commit comments

Comments
 (0)
0