Loading core/modules/locale/src/LocaleXss.php +3 Changes for core/modules/locale/src/LocaleXss.php: 3 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -56,6 +56,9 @@ public static function stringIsSafe(string $string): bool { // \Drupal\Component\Utility\Xss::filter() to not incorrectly alter the // string. https://www.drupal.org/node/2372127 $string = preg_replace('/\[[a-z0-9_-]+(:[a-z0-9_-]+)+\]/i', '', $string); // Remove the "<front>" placeholder if it exists, before testing with the // XSS filter, as it looks like an invalid HTML tag while it's a Drupalism. $string = str_replace('<front>', '', $string); return Html::decodeEntities($string) == Html::decodeEntities(Xss::filter($string, [ 'a', Loading core/modules/locale/tests/src/Kernel/LocaleStringIsSafeTest.php +10 Changes for core/modules/locale/tests/src/Kernel/LocaleStringIsSafeTest.php: 10 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -49,6 +49,16 @@ public function testLocaleStringIsSafe(): void { $result = LocaleXss::stringIsSafe($string); $this->assertTrue($result); // Check a translatable string which includes the <front> placeholder. $string = 'Enter <front> to link to the front page.'; $result = LocaleXss::stringIsSafe($string); $this->assertTrue($result); // Check that the <front> placeholder does not make unsafe HTML safe. $string = 'Enter <front> <script>alert("unsafe");</script>'; $result = LocaleXss::stringIsSafe($string); $this->assertFalse($result); // Check a translatable string which includes a wbr tag. $string = 'DrupalLocaleModule<wbr>Test<wbr>Example'; $result = LocaleXss::stringIsSafe($string); Loading Loading
core/modules/locale/src/LocaleXss.php +3 Changes for core/modules/locale/src/LocaleXss.php: 3 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -56,6 +56,9 @@ public static function stringIsSafe(string $string): bool { // \Drupal\Component\Utility\Xss::filter() to not incorrectly alter the // string. https://www.drupal.org/node/2372127 $string = preg_replace('/\[[a-z0-9_-]+(:[a-z0-9_-]+)+\]/i', '', $string); // Remove the "<front>" placeholder if it exists, before testing with the // XSS filter, as it looks like an invalid HTML tag while it's a Drupalism. $string = str_replace('<front>', '', $string); return Html::decodeEntities($string) == Html::decodeEntities(Xss::filter($string, [ 'a', Loading
core/modules/locale/tests/src/Kernel/LocaleStringIsSafeTest.php +10 Changes for core/modules/locale/tests/src/Kernel/LocaleStringIsSafeTest.php: 10 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -49,6 +49,16 @@ public function testLocaleStringIsSafe(): void { $result = LocaleXss::stringIsSafe($string); $this->assertTrue($result); // Check a translatable string which includes the <front> placeholder. $string = 'Enter <front> to link to the front page.'; $result = LocaleXss::stringIsSafe($string); $this->assertTrue($result); // Check that the <front> placeholder does not make unsafe HTML safe. $string = 'Enter <front> <script>alert("unsafe");</script>'; $result = LocaleXss::stringIsSafe($string); $this->assertFalse($result); // Check a translatable string which includes a wbr tag. $string = 'DrupalLocaleModule<wbr>Test<wbr>Example'; $result = LocaleXss::stringIsSafe($string); Loading