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
Fix Undefined offset: 0 #1894
Fix Undefined offset: 0 #1894
Conversation
Can you please provide some examples how you met this issue? Examining the code this should not be possible at all. |
In the fromString method of
An error occurred because the 0th array did not exist.
|
Related: #1895 http://php.net/manual/en/function.array-filter.php Iterates over each value in the array passing them to the callback function. If the callback function returns true, the current value from array is returned into the result array. Array keys are preserved. |
It would be easy to write a test for this. Could you provide a test that is proving the correctness of this patch? |
Test cases added. |
Oh my.... of course it does. Thanks a lot for the fix. Will merge and tag once the build passes. |
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.
Thank you @e1111o. I like that you added a test. But your test does not prove the correctness of the patch.
Actually, your patch does not do anything with this input date.
@Nyholm Thank you for your care. |
I think you miss the point. Im saying that the test you provided will pass with and without you changes to SetCookie.php. I need you to provide a test that would fail without your changes to SetCookie.php. Such test will prove the correctness of your patch. |
What's the status of this PR? |
Sorry. I have been busy with my company business these days and have not progressed since. I'll commit it soon after the fix. |
I encountered this bug myself just now. I've looked at the proposed changes in the aforementioned pull request, but I don't believe they address the real issue. This error is triggered when the first KVP (key-value pair) in a Set-Cookie string is missing. This KVP is pretty vital to the cookie because it provides the cookie's name and value. I'm not familiar with the relevant RFCs or other standards regarding cookie handling, but I would guess this isn't legal. But what action should Guzzle take in this case? It seems to me that a cookie without a name and value is dead on arrival and should be ignored. The code in question already has a comment indicating that it expects the cookie to have that first KVP. See line 38:
The proposed fix only re-indexes the So I believe this pull request should indeed be rejected, even without looking at the tests. I'm considering submitting my own pull request which would fix this more properly, if I can find time today or tomorrow. |
I've submitted a pull request. See #1998. I saw that the function in question already returns an empty cookie object if the cookie is missing a name, so I made a trivial fix which also does that if the whole first key-value pair is missing. For clarification, this bug is only triggered if the |
A better fix for #1894 - "Undefined offset: 0"
Accepted the fix in #1998 Thanks for your contribution though |
No description provided.