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

[4.x]: attr filter double-encoding existing class and style attributes #12887

Closed
mmikkel opened this issue Mar 14, 2023 · 2 comments
Closed

[4.x]: attr filter double-encoding existing class and style attributes #12887

mmikkel opened this issue Mar 14, 2023 · 2 comments
Assignees

Comments

@mmikkel
Copy link
Contributor

mmikkel commented Mar 14, 2023

What happened?

Description

If the attr filter is applied to a tag that already had its attributes encoded, any exploded attributes like class and style, will become double-encoded.

The reason seems to be that Html::parseTagAttributes() doesn't account for exploded attributes:

if (is_string($value)) {

Related: #12886

Steps to reproduce

Applying multiple |attr filters to the same tag will double encode ampersands (i.e. to & instead of the expected &) in the class attribute:

{% apply attr({ disabled: true })|attr({ type: 'button' }) %}
    <button class="[&[disabled]]:opacity-50">
{% endapply %}

The double-encoding also happens if a tag is rendered using the {% tag %} tag or tag() function, and then has the attr filter applied to it:

{{ tag('button', { class: '[&[disabled]]:opacity-50' })|attr({ disabled: true }) }}

Expected behavior

The attr filter should never double-encode existing attributes.

Actual behavior

The attr filter will double-encode certain existing attributes, such as class and style.

Craft CMS version

4.4.1

PHP version

8.1.12

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

None

@brandonkelly
Copy link
Member

Thanks for reporting! Craft 3.8.2 and 4.4.2 are out now with a fix.

@mmikkel
Copy link
Contributor Author

mmikkel commented Mar 14, 2023

Awesome, thanks a lot Brandon 🚀

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

2 participants