diff --git a/core/lib/Drupal/Component/Utility/SafeMarkup.php b/core/lib/Drupal/Component/Utility/SafeMarkup.php index 60b3b35..090a73c 100644 --- a/core/lib/Drupal/Component/Utility/SafeMarkup.php +++ b/core/lib/Drupal/Component/Utility/SafeMarkup.php @@ -74,6 +74,11 @@ class SafeMarkup { * The input string that was marked as safe. */ public static function set($string, $strategy = 'html') { + // Start or increment a counter when a string is marked as safe. This allows + // strings to be removed from the array just before printing with + // \Drupal\Component\Utility\SafeMarkup::remove() in order to conserve + // memory, while accounting for identical strings used within the same + // request. $string = (string) $string; if (!isset(static::$safeStrings[$string][$strategy])) { static::$safeStrings[$string][$strategy] = 1; @@ -99,6 +104,8 @@ public static function set($string, $strategy = 'html') { * - 'all': The string is safe for all use cases. */ public static function remove($string, $strategy = 'html') { + // Remove the string if it's only been marked as safe once, otherwise + // decrement the counter. $string = (string) $string; if (isset(static::$safeStrings[$string][$strategy])) { if (static::$safeStrings[$string][$strategy] == 1) { diff --git a/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php b/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php index 5e5bf00..5e03f9b 100644 --- a/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php +++ b/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php @@ -263,7 +263,9 @@ protected function prepare(array $main_content, Request $request, RouteMatchInte $this->invokePageAttachmentHooks($page); // Determine the title: use the title provided by the main content if any, - // otherwise get it from the routing information. + // otherwise get it from the routing information. The title provided by the + // main content was escaped when rendered above. Explicitly mark it as safe + // here when re-using the string to avoid double-escaping. $title = isset($main_content['#title']) ? SafeMarkup::set($main_content['#title']) : $this->titleResolver->getTitle($request, $route_match->getRouteObject()); return [$page, $title];