Commit 015d03ed authored by catch's avatar catch
Browse files

fix: #3473763 locale_string_is_safe should accept "<front>" as being safe

By: jurgenhaas
By: smustgrave
(cherry picked from commit 1f24b84b)
parent 58c1deba
Loading
Loading
Loading
Loading
Loading
+3
Changes for core/modules/locale/src/LocaleXss.php: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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',
+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
@@ -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);