diff --git a/core/lib/Drupal/Core/Utility/LinkGenerator.php b/core/lib/Drupal/Core/Utility/LinkGenerator.php
index ab2d232..adfa6f2 100644
--- a/core/lib/Drupal/Core/Utility/LinkGenerator.php
+++ b/core/lib/Drupal/Core/Utility/LinkGenerator.php
@@ -141,10 +141,9 @@ public function generate($text, Url $url, $collect_cacheability_metadata = FALSE
       $generated_link = GeneratedLink::createFromObject($generated_url);
     }
 
-    // Make sure the link text is sanitized.
-    $safe_text = SafeMarkup::escape($variables['text']);
+    // All attributes are safe because all subclasses of AttributeValueBase call checkPlain in __toString()
+    $result = SafeMarkup::format('<a href="@url"' . $attributes . '>@text</a>', ['@url' => $url, '@text' => $variables['text']]);
 
-    $result = SafeMarkup::set('<a href="' . $url . '"' . $attributes . '>' . $safe_text . '</a>');
     return $collect_cacheability_metadata ? $generated_link->setGeneratedLink($result) : $result;
   }
 
