Skip to content
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

Twig map filter can not use key #3591

Open
kingschnulli opened this issue Mar 5, 2024 · 4 comments
Open

Twig map filter can not use key #3591

kingschnulli opened this issue Mar 5, 2024 · 4 comments
Labels
Bug Good first issue Good Issue for your first contribution or experimenting with Shopware

Comments

@kingschnulli
Copy link
Contributor

PHP Version

Any

Shopware Version

6.5.8.6 / trunk

Expected behaviour

Consider the following twig template in storefront, reduced for clarity:

{% set itemStyles = {
    border: '1px solid #000',
    padding: '15px'
%}
<div style="{{ itemStyles|map((cssValue, cssProperty) => "#{cssProperty}: #{cssValue}")|join(';') }}">
...
</div>

This will fail with an exception from SecurityExtension

Too few arguments to function __TwigTemplate_e2e6dd84c91e95ce276fd9aafe10abd0::{closure}(), 1 passed in /var/www/html/vendor/shopware/core/Framework/Adapter/Twig/SecurityExtension.php on line 54 and exactly 2 expected

The SecurityExtension ignores the fact that Twigs map function closure can take up to 2 arguments - see Twig Docs

Actual behaviour

The twig compiler should not fail, map is an allowed function and should work as expected.

How to reproduce

Run the twig template in the storefront:

{% set itemStyles = {
    border: '1px solid #000',
    padding: '15px'
%}
<div style="{{ itemStyles|map((cssValue, cssProperty) => "#{cssProperty}: #{cssValue}")|join(';') }}">
test
</div>
@shyim
Copy link
Member

shyim commented Mar 5, 2024

Can you make a PR? should be simple fixed :)

@shyim shyim added the QuickPick label Mar 5, 2024
@kingschnulli
Copy link
Contributor Author

Sure will do - just wanted to know if this is was intended or a bug

@shyim
Copy link
Member

shyim commented Mar 5, 2024

It was not intended :)

@mitelg mitelg added the Good first issue Good Issue for your first contribution or experimenting with Shopware label Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Good first issue Good Issue for your first contribution or experimenting with Shopware
Projects
None yet
Development

No branches or pull requests

4 participants