Skip to content

AbstractSurrogateFragmentRenderer does not detect non-scalar attributes reliably #46152

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
m-vo opened this issue Apr 24, 2022 · 2 comments
Closed

Comments

@m-vo
Copy link
Contributor

m-vo commented Apr 24, 2022

Symfony version(s) affected

4.4 - current

Description

The AbstractSurrogateFragmentRenderer throws an exception if non-scalar values are passed as attributes, but the detection has an early returns in case an attribute's $value is an array:

private function containsNonScalars(array $values): bool
{
foreach ($values as $value) {
if (\is_array($value)) {
return $this->containsNonScalars($value);
} elseif (!is_scalar($value) && null !== $value) {
return true;
}
}
return false;
}

How to reproduce

Pass on attributes in the form [[], <non-scalar>], containsNonScalars will return false instead of true.

Possible Solution

Something like this:

private function containsNonScalars(array $values): bool
{
    foreach ($values as $value) {
        if (\is_array($value) && $this->containsNonScalars($value)) {
            return true;
        }

        if (!is_scalar($value) && null !== $value) {
            return true;
        }
    }
}

Additional Context

No response

@chalasr
Copy link
Member

chalasr commented May 17, 2022

Would you mind opening a PR?

@aschempp
Copy link
Contributor

see #47073

@fabpot fabpot closed this as completed Jul 27, 2022
nicolas-grekas added a commit that referenced this issue Jul 29, 2022
…nderer (aschempp)

This PR was merged into the 4.4 branch.

Discussion
----------

[HttpKernel] Fix non-scalar check in surrogate fragment renderer

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #46152
| License       | MIT
| Doc PR        | -

Commits
-------

6b85cfd [HttpKernel] Fix non-scalar check in surrogate fragment renderer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants