diff --git a/core/lib/Drupal/Component/Utility/EscapedString.php b/core/lib/Drupal/Component/Render/EscapedMarkup.php similarity index 68% rename from core/lib/Drupal/Component/Utility/EscapedString.php rename to core/lib/Drupal/Component/Render/EscapedMarkup.php index 9a3dcd8..a6fd863 100644 --- a/core/lib/Drupal/Component/Utility/EscapedString.php +++ b/core/lib/Drupal/Component/Render/EscapedMarkup.php @@ -2,17 +2,20 @@ /** * @file - * Contains \Drupal\Component\Utility\EscapedString. + * Contains \Drupal\Component\Render\EscapedMarkup. */ -namespace Drupal\Component\Utility; +namespace Drupal\Component\Render; + +use Drupal\Component\Utility\Html; +use Drupal\Component\Utility\Unicode; /** - * Escapes a string for HTML display. + * Escapes a string for display in markup. * * @ingroup sanitization */ -class EscapedString implements EscapedStringInterface { +class EscapedMarkup implements EscapedMarkupInterface { /** * The string to escape. @@ -22,7 +25,7 @@ class EscapedString implements EscapedStringInterface { protected $string; /** - * Constructs an EscapedString object. + * Constructs an EscapedMarkup object. * * @param $string * The string to escape. This value will be cast to a string. diff --git a/core/lib/Drupal/Component/Render/EscapedMarkupInterface.php b/core/lib/Drupal/Component/Render/EscapedMarkupInterface.php new file mode 100644 index 0000000..7efc291 --- /dev/null +++ b/core/lib/Drupal/Component/Render/EscapedMarkupInterface.php @@ -0,0 +1,27 @@ + $value) { - $replacements[$token] = SafeMarkup::isSafe($value) ? $value : Html::escape($value); + $replacements[$token] = $value instanceof MarkupInterface ? $value : new EscapedMarkup($value); } // Optionally alter the list of replacement values. diff --git a/core/tests/Drupal/Tests/Component/Utility/SafeMarkupTest.php b/core/tests/Drupal/Tests/Component/Utility/SafeMarkupTest.php index f50f4f1..f654fb7 100644 --- a/core/tests/Drupal/Tests/Component/Utility/SafeMarkupTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/SafeMarkupTest.php @@ -7,7 +7,7 @@ namespace Drupal\Tests\Component\Utility; -use Drupal\Component\Utility\EscapedString; +use Drupal\Component\Render\EscapedMarkup; use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Render\MarkupInterface; use Drupal\Component\Render\MarkupTrait; @@ -58,27 +58,27 @@ public function testIsSafe() { */ function testCheckPlain($text, $expected, $message) { $result = SafeMarkup::checkPlain($text); - $this->assertTrue($result instanceof EscapedString); + $this->assertTrue($result instanceof EscapedMarkup); $this->assertEquals($expected, $result, $message); } /** - * Tests Drupal\Component\Utility\EscapedString. + * Tests Drupal\Component\Render\EscapedMarkup. * * Verifies that the result of SafeMarkup::checkPlain() is the same as - * using EscapedString directly. + * using EscapedMarkup directly. * * @dataProvider providerCheckPlain * * @param string $text - * The text to provide to the EscapedString constructor. + * The text to provide to the EscapedMarkup constructor. * @param string $expected * The expected output from the function. * @param string $message * The message to provide as output for the test. */ function testEscapeString($text, $expected, $message) { - $result = new EscapedString($text); + $result = new EscapedMarkup($text); $this->assertEquals($expected, $result, $message); }