diff --git a/core/lib/Drupal/Core/Utility/LinkGenerator.php b/core/lib/Drupal/Core/Utility/LinkGenerator.php
index abab213..9bc00d3 100644
--- a/core/lib/Drupal/Core/Utility/LinkGenerator.php
+++ b/core/lib/Drupal/Core/Utility/LinkGenerator.php
@@ -130,8 +130,9 @@ public function generate($text, Url $url, $collect_cacheability_metadata = FALSE
unset($variables['options']['attributes']);
$url->setOptions($variables['options']);
- // The result of the url generator is a plain-text URL. Because we are using
- // it here in an HTML argument context, we encode it below with SafeFormat::format
+ // The result of the url generator is a plain-text URL.
+ // We encode it below with SafeMarkup::format because we are using it here
+ // in an HTML argument context.
if (!$collect_cacheability_metadata) {
$url = $url->toString($collect_cacheability_metadata);
}
@@ -141,8 +142,7 @@ public function generate($text, Url $url, $collect_cacheability_metadata = FALSE
$generated_link = GeneratedLink::createFromObject($generated_url);
}
- // $attributes are safe because all subclasses of AttributeValueBase call checkPlain in their __toString()
- $result = SafeMarkup::format('@text', ['@url' => $url, '@text' => $variables['text']]);
+ $result = SafeMarkup::format('@text', ['@url' => $url, '@attributes' => $attributes, '@text' => $variables['text']]);
return $collect_cacheability_metadata ? $generated_link->setGeneratedLink($result) : $result;
}