Commit fdf37cf3 authored by catch's avatar catch

Issue #2958407 by alexpott: Properly deprecate SafeMarkup::isSafe,...

Issue #2958407 by alexpott: Properly deprecate SafeMarkup::isSafe, SafeMarkup::checkPlain and the SafeMarkup class
parent 68b8b52f
......@@ -40,6 +40,7 @@ class SafeMarkup {
* @see https://www.drupal.org/node/2549395
*/
public static function isSafe($string, $strategy = 'html') {
@trigger_error('SafeMarkup::isSafe() is scheduled for removal in Drupal 9.0.0. Instead, you should just check if a variable is an instance of \Drupal\Component\Render\MarkupInterface. See https://www.drupal.org/node/2549395.', E_USER_DEPRECATED);
return $string instanceof MarkupInterface;
}
......@@ -66,6 +67,7 @@ public static function isSafe($string, $strategy = 'html') {
* @see drupal_validate_utf8()
*/
public static function checkPlain($text) {
@trigger_error('SafeMarkup::checkPlain() is scheduled for removal in Drupal 9.0.0. Rely on Twig\'s auto-escaping feature, or use the @link theme_render #plain_text @endlink key when constructing a render array that contains plain text in order to use the renderer\'s auto-escaping feature. If neither of these are possible, \Drupal\Component\Utility\Html::escape() can be used in places where explicit escaping is needed. See https://www.drupal.org/node/2549395.', E_USER_DEPRECATED);
return new HtmlEscapedText($text);
}
......
......@@ -18,7 +18,6 @@
*
* @see \Drupal\Core\Template\TwigExtension::escapeFilter
* @see \Twig_Markup
* @see \Drupal\Component\Utility\SafeMarkup
*/
final class Markup implements MarkupInterface, \Countable {
use MarkupTrait;
......
......@@ -43,7 +43,7 @@ protected function doLeaveNode(\Twig_Node $node, \Twig_Environment $env) {
elseif ($node instanceof \Twig_Node_Expression_Filter) {
$name = $node->getNode('filter')->getAttribute('value');
if ('escape' == $name || 'e' == $name) {
// Use our own escape filter that is SafeMarkup aware.
// Use our own escape filter that is MarkupInterface aware.
$node->getNode('filter')->setAttribute('value', 'drupal_escape');
// Store that we have a filter active already that knows
......
......@@ -37,8 +37,7 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
protected $testLanguageSelector = TRUE;
/**
* Flag that tells whether the HTML escaping of all languages works or not
* after SafeMarkup change.
* Flag to determine if "all languages" rendering is tested.
*
* @var bool
*/
......@@ -117,8 +116,7 @@ protected function doTestBasicTranslation() {
], ['language' => $language]);
$this->drupalPostForm($add_url, $this->getEditValues($values, $langcode), $this->getFormSubmitActionForNewTranslation($entity, $langcode));
// Assert that HTML is escaped in "all languages" in UI after SafeMarkup
// change.
// Assert that HTML is not escaped unexpectedly.
if ($this->testHTMLEscapeForAllLanguages) {
$this->assertNoRaw('<span class="translation-entity-all-languages">(all languages)</span>');
$this->assertRaw('<span class="translation-entity-all-languages">(all languages)</span>');
......
......@@ -35,8 +35,7 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
protected $testLanguageSelector = TRUE;
/**
* Flag that tells whether the HTML escaping of all languages works or not
* after SafeMarkup change.
* Flag to determine if "all languages" rendering is tested.
*
* @var bool
*/
......@@ -115,8 +114,7 @@ protected function doTestBasicTranslation() {
], ['language' => $language]);
$this->drupalPostForm($add_url, $this->getEditValues($values, $langcode), $this->getFormSubmitActionForNewTranslation($entity, $langcode));
// Assert that HTML is escaped in "all languages" in UI after SafeMarkup
// change.
// Assert that HTML is not escaped unexpectedly.
if ($this->testHTMLEscapeForAllLanguages) {
$this->assertNoRaw('&lt;span class=&quot;translation-entity-all-languages&quot;&gt;(all languages)&lt;/span&gt;');
$this->assertRaw('<span class="translation-entity-all-languages">(all languages)</span>');
......
......@@ -18,6 +18,7 @@
* Tests marking strings as safe.
*
* @group Utility
* @group legacy
* @coversDefaultClass \Drupal\Component\Utility\SafeMarkup
*/
class SafeMarkupTest extends TestCase {
......@@ -35,6 +36,7 @@ protected function tearDown() {
* Tests SafeMarkup::isSafe() with different objects.
*
* @covers ::isSafe
* @expectedDeprecation SafeMarkup::isSafe() is scheduled for removal in Drupal 9.0.0. Instead, you should just check if a variable is an instance of \Drupal\Component\Render\MarkupInterface. See https://www.drupal.org/node/2549395.
*/
public function testIsSafe() {
$safe_string = $this->getMockBuilder('\Drupal\Component\Render\MarkupInterface')->getMock();
......@@ -48,6 +50,7 @@ public function testIsSafe() {
*
* @dataProvider providerCheckPlain
* @covers ::checkPlain
* @expectedDeprecation SafeMarkup::checkPlain() is scheduled for removal in Drupal 9.0.0. Rely on Twig's auto-escaping feature, or use the @link theme_render #plain_text @endlink key when constructing a render array that contains plain text in order to use the renderer's auto-escaping feature. If neither of these are possible, \Drupal\Component\Utility\Html::escape() can be used in places where explicit escaping is needed. See https://www.drupal.org/node/2549395.
*
* @param string $text
* The text to provide to SafeMarkup::checkPlain().
......@@ -125,10 +128,6 @@ public function testFormat($string, array $args, $expected, $message, $expected_
$result = SafeMarkup::format($string, $args);
$this->assertEquals($expected, (string) $result, $message);
$this->assertEquals($expected_is_safe, $result instanceof MarkupInterface, 'SafeMarkup::format correctly sets the result as safe or not safe.');
foreach ($args as $arg) {
$this->assertSame($arg instanceof SafeMarkupTestMarkup, SafeMarkup::isSafe($arg));
}
}
/**
......
......@@ -110,7 +110,6 @@ public function testGetDataDefinition($is_multiple) {
* @dataProvider providerGetDataDefinition
* @covers ::getDataDefinition
* @uses \Drupal
* @uses \Drupal\Component\Utility\SafeMarkup
*/
public function testGetDataDefinitionInvalidType($is_multiple) {
// Since we're trying to make getDataDefinition() throw an exception in
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment