Skip to content

[HttpKernel] changed the fragment handler to explicitely disallow non-scalar in generated URIs (refs #8263) #8437

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

Merged
merged 2 commits into from
Jul 15, 2013

Conversation

fabpot
Copy link
Member

@fabpot fabpot commented Jul 8, 2013

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #8263
License MIT
Doc PR n/a

When using the render() function in Twig with a controller() reference, the attributes can contain non-scalar. That's fine for the inline strategy, but it cannot work for other strategies as it then involves a proper HTTP request.

So, this PR properly throw an exception in such situations to avoid difficult to find bugs.

@@ -56,4 +61,17 @@ protected function generateFragmentUri(ControllerReference $reference, Request $

return $request->getUriForPath($this->fragmentPath.'?'.http_build_query($reference->query, '', '&'));
}

private function checkNonScalar($values)
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this be typehinted as array ?

}

if (!is_scalar($value)) {
throw new \LogicException('Controller attributes cannot contain non-scalar values.');
Copy link
Member

Choose a reason for hiding this comment

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

Can you add the "key" of the value to message ? It will be easier to debug with it.

if (is_array($value)) {
$this->checkNonScalar($value);
} elseif (!is_scalar($value)) {
throw new \LogicException(sprintf('Controller attributes cannot contain non-scalar values (value for key "%s" is not a scalar).', $key));
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe also add gettype($value) to show the actual type passed

fabpot added a commit that referenced this pull request Jul 15, 2013
This PR was merged into the master branch.

Discussion
----------

[HttpKernel] changed the fragment handler to explicitely disallow non-scalar in generated URIs (refs #8263)

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #8263
| License       | MIT
| Doc PR        | n/a

When using the `render()` function in Twig with a `controller()` reference, the attributes can contain non-scalar. That's fine for the inline strategy, but it cannot work for other strategies as it then involves a proper HTTP request.

So, this PR properly throw an exception in such situations to avoid difficult to find bugs.

Commits
-------

43ce368 [HttpKernel] added a unit test to demonstrate that passing objects works for inline controllers
70f3399 [HttpKernel] changed the fragment handler to explicitely disallow non-scalar in generated URIs (refs #8263)
@fabpot fabpot merged commit 43ce368 into symfony:master Jul 15, 2013
@lolautruche
Copy link
Contributor

Could this be merged to 2.3 branch ?
This prevents eZ Publish to be forward compatible with Symfony >=2.4 as we extend fragment renderers.

Thanks

@stof
Copy link
Member

stof commented Apr 7, 2014

New features are never backported to older versions.

Your issue here is that you are using in the class in a way which is not covered by our BC promise: http://symfony.com/bc
The class is not yet part of the tagged API (at least it was not at the time of this change), which means that adding a new argument to tbe overriden method is not covered

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.

5 participants