-
Notifications
You must be signed in to change notification settings - Fork 24
[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
base: main
Are you sure you want to change the base?
Conversation
|
||
foreach ($attributes as $name => $value) { | ||
$result[sprintf('data-test-%s', $name)] = (string) $value; | ||
$escapedValue = htmlspecialchars((string) $value, \ENT_QUOTES | \ENT_SUBSTITUTE, 'UTF-8'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) }}
There was a problem hiding this comment.
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
There was a problem hiding this 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.
No description provided.