-
Notifications
You must be signed in to change notification settings - Fork 39
Implements a cookie-date parsing utility #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/CookieUtil.php
Outdated
* @var array | ||
*/ | ||
private static $dateFormats = array( | ||
'D, d M y H:i:s T', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add the format "Tuesday, 31 Mar 99 07:42:12 GMT" at the line 14 mentionned in php-http/client-common#46
src/CookieUtil.php
Outdated
* @see https://github.com/symfony/symfony/blob/master/src/Symfony/Component/BrowserKit/Cookie.php | ||
* | ||
* @param string $dateValue | ||
* @return \DateTime|false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I rather throw an exception ?
eec2be5
to
e83fd58
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks. i agree to not create a dependency on symfony browser kit for just this function.
just one question: is date_create alone not good enough?
CHANGELOG.md
Outdated
@@ -3,6 +3,10 @@ | |||
|
|||
## Unreleased | |||
|
|||
### |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use the title "Added" here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix
@dbu if we use only date_create, the tests will fail for this format |
But this format is not conform to the rfc https://tools.ietf.org/html/rfc6265#section-5.1.1
it has been added to manage unusual cookie dates, see commit symfony/browser-kit@47f146d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the clarification. seems good then, +1 from me.
regarding the build fail, thats a hhvm setup issue. i created #77. if we want to be dead sure it all works out, we can wait for that to merge and then rebase this branch on master afterwards.
e3ce2ef
to
b4d1e0e
Compare
Rebase done I added more tests from library mentioned in php-http/client-common#46 https://github.com/salesforce/tough-cookie/blob/master/test/date_test.js except Use only the function Maybe, |
tests failed on PHP 5.4 and HHVM |
I will fix later http://php.net/manual/en/class.datetime.php#datetime.changelog
|
as hhvm works on master, did we just discover a difference between hhvm and php here? the php 5.4 build fails on the same things, formatting the date: it seems to me that |
src/CookieUtil.php
Outdated
* | ||
* @param string $dateValue | ||
* | ||
* @return \DateTime|false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would prefer throwing an exception when the date can't be parsed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a php exception like UnexpectedValueException
or Http\Message\Exception\UnexpectedValueException
?
Yes it is |
d5ec782
to
caa5344
Compare
throws an exception when the date can't be parsed and commits squashed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a cookie date expert, but looks good to me.
thanks a lot @aaa2000 ! |
What's in this PR?
Implementation of a cookie-date parsing algorithm mentionned in php-http/client-common#46. I preferred to use a simpler method from https://github.com/symfony/symfony/blob/master/src/Symfony/Component/BrowserKit/Cookie.php#L199.
Example Usage
Checklist