8000 Expanded fault-tolerance for unusual cookie dates by ecaron · Pull Request #7149 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Expanded fault-tolerance for unusual cookie dates #7149

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

Closed
wants to merge 4 commits into from
Closed

Expanded fault-tolerance for unusual cookie dates #7149

wants to merge 4 commits into from

Conversation

ecaron
Copy link
Contributor
@ecaron ecaron commented Feb 21, 2013

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.

…time

fault-tolerance for cookies that have very unusual date formatting
@@ -205,6 +207,11 @@ private static function parseDate($dateValue)
}
}

// attempt a fallback for unusual formatting
if (false !== $dateTimestamp = strtotime($dateValue)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about the TZ handling ?

@vicb
Copy link
Contributor
vicb commented Feb 21, 2013

Please add some unit tests for the new formats.

@ecaron
Copy link
Contributor Author
ecaron commented Feb 21, 2013

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.

@ecaron
Copy link
Contributor Author
ecaron commented Feb 21, 2013

@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?

@@ -205,6 +207,11 @@ private static function parseDate($dateValue)
}
}

// attempt a fallback for unusual formatting
if (false !== $date = date_create($dateValue, new \DateTimeZone('GMT'))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tabs ? Sf use 4 spaces for indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Believe me - I got a bit nauseous when I saw that slip through. I thought that Scrutinizer's auto-change got merged back into this pull. I'll update.

@vicb
Copy link
Contributor
vicb commented Feb 21, 2013

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)

@@ -205,6 +207,11 @@ private static function parseDate($dateValue)
}
}

// attempt a fallback for unusual formatting
if (false !== $date = date_create($dateValue, new \DateTimeZone('GMT'))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use UTC rather than GMT, per http://www.php.net/manual/en/timezones.others.php

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that be out of the scope of this pull, given the two other existing places in Cookie.php that already invoke GMT rather than the preferred UTC?

@fabpot
Copy link
Member
fabpot commented Feb 21, 2013

This should probably go into 2.0. Also, do you have a reference where those 7 formats are explained/described?

@ecaron
Copy link
Contributor Author
ecaron commented Feb 21, 2013

@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.

fabpot added a commit that referenced this pull request Feb 22, 2013
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.
@fabpot
Copy link
Member
fabpot commented Feb 22, 2013

merged in 2.1, thanks.

@fabpot fabpot closed this Feb 22, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0