function AttributeTest::providerTestAttributeValues
Same name and namespace in other branches
- 11.x core/tests/Drupal/Tests/Core/Template/AttributeTest.php \Drupal\Tests\Core\Template\AttributeTest::providerTestAttributeValues()
- 10 core/tests/Drupal/Tests/Core/Template/AttributeTest.php \Drupal\Tests\Core\Template\AttributeTest::providerTestAttributeValues()
- 9 core/tests/Drupal/Tests/Core/Template/AttributeTest.php \Drupal\Tests\Core\Template\AttributeTest::providerTestAttributeValues()
- 8.9.x core/tests/Drupal/Tests/Core/Template/AttributeTest.php \Drupal\Tests\Core\Template\AttributeTest::providerTestAttributeValues()
File
-
core/
tests/ Drupal/ Tests/ Core/ Template/ AttributeTest.php, line 390
Class
Namespace
Drupal\Tests\Core\TemplateCode
public static function providerTestAttributeValues() : array {
$data = [
'HTML-encoded attribute name' => [
[
'&"\'<>' => 'value',
],
' &"'<>="value"',
],
'HTML-encoded attribute value' => [
[
'title' => '&"\'<>',
],
' title="&"'<>"',
],
'multi-value attribute' => [
[
'class' => [
'first',
'last',
],
],
' class="first last"',
],
'true boolean attribute' => [
[
'disabled' => TRUE,
],
' disabled',
],
'false boolean attribute' => [
[
'disabled' => FALSE,
],
'',
],
'empty attribute value' => [
[
'alt' => '',
],
' alt=""',
],
'null attribute value' => [
[
'alt' => NULL,
],
'',
],
'multiple attributes' => [
[
'id' => 'id-test',
'class' => [
'first',
'last',
],
'alt' => 'Alternate',
],
' id="id-test" class="first last" alt="Alternate"',
],
'empty attributes array' => [
[],
'',
],
];
$string = '"> <script>alert(123)</script>"';
$data['safe-object-xss1'] = [
[
'title' => Markup::create($string),
],
' title=""> alert(123)""',
];
$data['non-safe-object-xss1'] = [
[
'title' => $string,
],
' title="' . Html::escape($string) . '"',
];
$string = '"><script>alert(123)</script>';
$data['safe-object-xss2'] = [
[
'title' => Markup::create($string),
],
' title="">alert(123)"',
];
$data['non-safe-object-xss2'] = [
[
'title' => $string,
],
' title="' . Html::escape($string) . '"',
];
// \Twig\Markup objects are generated when using twig defined variables
// like `{% set xxx %}Foo{% endset %}`.
$data['twig-markup'] = [
[
'title' => new TwigMarkup('foo', 'UTF-8'),
],
' title="foo"',
];
return $data;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.