Skip to content

[TwigExtra] Escape potential html in test attributes #251

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mpysiak
Copy link
Member

@mpysiak mpysiak commented Apr 23, 2025

No description provided.

@@ -43,7 +43,9 @@ function (array $attributes): array {
$result = [];

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

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.

2 participants