[BrowserKit] Cookie expiration at current timestamp #38360
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In
Symfony\Component\BrowserKit\Cookie
a cookie is expired if theexpires
timestamp is in the past. I would like to change it to also be expired if theexpires
timestamp equals the current exact timestamp. This would still be in line with RFC 6265, as it statesThe Expires attribute indicates the maximum lifetime of the cookie, represented as the date and time at which the cookie expires
.Reason for this change: Cookies usually both have
expires
andMax-Age
set, and Symfony setsMax-Age
to zero if a cookie is expired (inSymfony\Component\HttpFoundation\Cookie
). When converting cookies between string and object representations,Max-Age
is the preferred source of truth for the expiration, butMax-Age
set to zero is converted to anexpires
timestamp at this exact second, currently making the cookie not expired inSymfony\Component\BrowserKit\Cookie
, even though it should be.I noticed this discrepancy in my tests when checking if a cookie no longer existed after deleting it, yet it was still there, because
Cookie
thought it would only expire after theexpires
timestamp had passed. I am also thinking of raising an issue forSymfony\Component\HttpFoundation\Cookie
, as importing and exporting an expired cookie (via strings) changes theexpired
value. I thought this change was a simpler one for now, and should have no negative/unexpected impact.