Skip to content

Conversation

mpysiak
Copy link
Member

@mpysiak mpysiak commented Apr 23, 2025

No description provided.


foreach ($attributes as $name => $value) {
$result[sprintf('data-test-%s', $name)] = (string) $value;
$escapedValue = htmlspecialchars((string) $value, \ENT_QUOTES | \ENT_SUBSTITUTE, 'UTF-8');
Copy link
Member

Choose a reason for hiding this comment

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

My main opinion is that it'd be better to escape this in Twig itself to use escaper strategy. but maybe it'd be overkilled.

Copy link
Member Author

Choose a reason for hiding this comment

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

This won't be escaped in Twig because we're adding ['is_safe' => ['html']]. This tells Twig's escaper that the content is safe HTML, so it won't apply automatic escaping

Copy link
Member Author

@mpysiak mpysiak Apr 25, 2025

Choose a reason for hiding this comment

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

other option is to add in every twig

{{ sylius_test_html_attribute('test-button', value|escape) }}

Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if there are a lot test html that have this value. A lot of them are just empty data test attributes

Copy link
Member

@diimpp diimpp left a comment

Choose a reason for hiding this comment

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

I'm out of the loop and when and why this change is needed, but code looks good.

Escape used 3 times across two classes, so maybe escaping strategy could be extracted into separate class/function, but given it's just a twig test classes current calls looks good enough.

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.

3 participants