Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpKernel] Fixed RequestDataCollector handling of null header values. #20747

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 2 commits into from

Conversation

gmoreira
Copy link

@gmoreira gmoreira commented Dec 4, 2016

Q A
Branch? master
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

This PR references this discussion.

@ro0NL
Copy link
Contributor

ro0NL commented Dec 4, 2016

$response->headers->set('X-Foo-Bar', null); is invalid 😕 The API of $values is string|string[] (well.. string|array actually).

But it doesnt expect null at all. Hence remove().

@gmoreira
Copy link
Author

gmoreira commented Dec 4, 2016

@ro0NL You are correct, I should have noticed this. However, this brings up an interesting point, should the HeaderBag set() method protect against this being possible?

@ro0NL
Copy link
Contributor

ro0NL commented Dec 4, 2016

No, this is design by contract. We could however clarify the PHPdoc, ie. string|string[], and perhaps default an empty array to array('') for the sake of it.

Then there are also a few array_key_exists checks which shouldnt be needed imo.

@alcalyn
Copy link
Contributor

alcalyn commented Dec 4, 2016

Personnaly I don't use $headersBag->set('X-Foo-Bar', null);, but $headersBag->set('X-Foo-Bar', $myValue);, and unfortunately $myValue was sometimes null. It doesn't affect the behaviour until this bug.

I think that if we set null, it should just not appears in headers, and let an empty array in headers bag, like before 3.2. So I agree this PR.

@ro0NL
Copy link
Contributor

ro0NL commented Dec 4, 2016

Imo setting null equals setting an empty string; ie. a header value is a string.

and unfortunately $myValue was sometimes null

That doesnt mean you can just violate string|string[].

@gmoreira
Copy link
Author

gmoreira commented Dec 5, 2016

@nicolas-grekas would be interested in your opinion here.

@@ -125,7 +125,7 @@ public function collect(Request $request, Response $response, \Exception $except
continue;
}
if ('request_headers' === $key || 'response_headers' === $key) {
$value = array_map(function ($v) { return isset($v[1]) ? $v : $v[0]; }, $value);
$value = array_map(function ($v) { return isset($v[1]) ? $v : (isset($v[0]) ? $v[0] : null); }, $value);
Copy link
Member

Choose a reason for hiding this comment

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

To be even more defensive, I'd suggest: isset($v[0]) && !isset($v[1]) ? $v[0] : $v

Copy link
Author

Choose a reason for hiding this comment

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

Sure. With regards to the unit test however, would you omit this change to the unit test in order to not violate the current interface contract of the HeaderBag::set() method.

Copy link
Member

Choose a reason for hiding this comment

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

If it's green, let's do with for now.

@nicolas-grekas
Copy link
Member

👍

@fabpot
Copy link
Member

fabpot commented Dec 5, 2016

Is it really something for master only?

@nicolas-grekas
Copy link
Member

3.2!

@fabpot
Copy link
Member

fabpot commented Dec 5, 2016

Thank you @gmoreira.

fabpot added a commit that referenced this pull request Dec 5, 2016
…eader values. (Gabriel Moreira)

This PR was submitted for the master branch but it was merged into the 3.2 branch instead (closes #20747).

Discussion
----------

[HttpKernel] Fixed RequestDataCollector handling of null header values.

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

This PR references this [discussion](symfony/http-kernel@1fee784#commitcomment-20028839).

Commits
-------

adc4a26 [HttpKernel] Fixed RequestDataCollector handling of null header values.
@fabpot fabpot closed this Dec 5, 2016
@fabpot fabpot mentioned this pull request Dec 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.