diff --git a/core/lib/Drupal/Component/Utility/SafeMarkup.php b/core/lib/Drupal/Component/Utility/SafeMarkup.php index 2d5b22a..db7557e 100644 --- a/core/lib/Drupal/Component/Utility/SafeMarkup.php +++ b/core/lib/Drupal/Component/Utility/SafeMarkup.php @@ -82,7 +82,7 @@ public static function set($string, $strategy = 'html') { /** * Checks if a string is safe to output. * - * @param string $string + * @param string|\Drupal\Component\Utility\SafeStringInterface $string * The content to be checked. * @param string $strategy * The escaping strategy. See self::set(). Defaults to 'html'. @@ -91,6 +91,8 @@ public static function set($string, $strategy = 'html') { * TRUE if the string has been marked secure, FALSE otherwise. */ public static function isSafe($string, $strategy = 'html') { + // Do the instance of checks first to save unnecessarily casting the object + // to a string. return $string instanceOf SafeStringInterface || isset(static::$safeStrings[(string) $string][$strategy]) || isset(static::$safeStrings[(string) $string]['all']); } diff --git a/core/lib/Drupal/Component/Utility/SafeStringInterface.php b/core/lib/Drupal/Component/Utility/SafeStringInterface.php index f078faa..1414a37 100644 --- a/core/lib/Drupal/Component/Utility/SafeStringInterface.php +++ b/core/lib/Drupal/Component/Utility/SafeStringInterface.php @@ -8,7 +8,7 @@ namespace Drupal\Component\Utility; /** - * Marks an objects __toString() method as returning safe markup. + * Marks an object's __toString() method as returning safe markup. */ interface SafeStringInterface { }