-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. other option is to add in every twig
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
$result[sprintf('data-test-%s', $name)] = $escapedValue; | ||
} | ||
|
||
return ['attr' => $result]; | ||
|
@@ -59,7 +61,9 @@ function (array $attributes): array { | |
public function getTestFormAttribute(string $name, ?string $value = null): array | ||
{ | ||
if (str_starts_with($this->environment, 'test') || $this->isDebugEnabled) { | ||
return ['attr' => ['data-test-' . $name => (string) $value]]; | ||
$escapedValue = htmlspecialchars((string) $value, \ENT_QUOTES | \ENT_SUBSTITUTE, 'UTF-8'); | ||
|
||
return ['attr' => ['data-test-' . $name => $escapedValue]]; | ||
} | ||
|
||
return []; | ||
|
Uh oh!
There was an error while loading. Please reload this page.