diff --git a/core/includes/batch.inc b/core/includes/batch.inc index 0958c3a365d5..77fd3a2231b9 100644 --- a/core/includes/batch.inc +++ b/core/includes/batch.inc @@ -47,14 +47,7 @@ function _batch_page(Request $request) { return new RedirectResponse(\Drupal::url('', [], ['absolute' => TRUE])); } } - // Restore safe strings from previous batches. - // This is safe because we are passing through the known safe values from - // SafeMarkup::getAll(). See _batch_shutdown(). - // @todo Ensure we are not storing an excessively large string list in: - // https://www.drupal.org/node/2295823 - if (!empty($batch['safe_strings'])) { - SafeMarkup::setMultiple($batch['safe_strings']); - } + // Register database update for the end of processing. drupal_register_shutdown_function('_batch_shutdown'); @@ -521,10 +514,6 @@ function _batch_finished() { */ function _batch_shutdown() { if ($batch = batch_get()) { - // Update safe strings. - // @todo Ensure we are not storing an excessively large string list in: - // https://www.drupal.org/node/2295823 - $batch['safe_strings'] = SafeMarkup::getAll(); \Drupal::service('batch.storage')->update($batch); } } diff --git a/core/includes/form.inc b/core/includes/form.inc index 16353d8d0b2f..48fa93f82233 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -6,7 +6,6 @@ */ use Drupal\Component\Utility\NestedArray; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\UrlHelper; use Drupal\Component\Utility\Xss; use Drupal\Core\Database\Database; @@ -701,8 +700,6 @@ function template_preprocess_form_element_label(&$variables) { * - css: Array of paths to CSS files to be used on the progress page. * - url_options: options passed to url() when constructing redirect URLs for * the batch. - * - safe_strings: Internal use only. Used to store and retrieve strings - * marked as safe between requests. * - progressive: A Boolean that indicates whether or not the batch needs to * run progressively. TRUE indicates that the batch will run in more than * one run. FALSE (default) indicates that the batch will finish in a single @@ -854,11 +851,6 @@ function batch_process($redirect = NULL, Url $url = NULL, $redirect_callback = N $request->query->remove('destination'); } - // Store safe strings. - // @todo Ensure we are not storing an excessively large string list in: - // https://www.drupal.org/node/2295823 - $batch['safe_strings'] = SafeMarkup::getAll(); - // Store the batch. \Drupal::service('batch.storage')->create($batch); diff --git a/core/lib/Drupal/Component/Render/HtmlEscapedText.php b/core/lib/Drupal/Component/Render/HtmlEscapedText.php new file mode 100644 index 000000000000..fd1e69d94ea6 --- /dev/null +++ b/core/lib/Drupal/Component/Render/HtmlEscapedText.php @@ -0,0 +1,61 @@ +string = (string) $string; + } + + /** + * {@inheritdoc} + */ + public function __toString() { + return Html::escape($this->string); + } + + /** + * {@inheritdoc} + */ + public function count() { + return Unicode::strlen($this->string); + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() { + return $this->__toString(); + } + +} diff --git a/core/lib/Drupal/Component/Render/MarkupInterface.php b/core/lib/Drupal/Component/Render/MarkupInterface.php index 2da4e13b7b26..65ab29a1a61c 100644 --- a/core/lib/Drupal/Component/Render/MarkupInterface.php +++ b/core/lib/Drupal/Component/Render/MarkupInterface.php @@ -31,6 +31,9 @@ namespace Drupal\Component\Render; * @see \Drupal\Component\Render\FormattableMarkup * @see \Drupal\Core\StringTranslation\TranslatableMarkup * @see \Drupal\views\Render\ViewsRenderPipelineMarkup + * @see twig_render_template() + * @see sanitization + * @see theme_render */ interface MarkupInterface extends \JsonSerializable { diff --git a/core/lib/Drupal/Component/Utility/SafeMarkup.php b/core/lib/Drupal/Component/Utility/SafeMarkup.php index 1272cee08e14..8d6387c1172e 100644 --- a/core/lib/Drupal/Component/Utility/SafeMarkup.php +++ b/core/lib/Drupal/Component/Utility/SafeMarkup.php @@ -7,26 +7,16 @@ namespace Drupal\Component\Utility; +use Drupal\Component\Render\HtmlEscapedText; use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Render\MarkupInterface; /** - * Manages known safe strings for rendering at the theme layer. + * Contains deprecated functionality related to sanitization of markup. * - * The Twig theme engine autoescapes string variables in the template, so it - * is possible for a string of markup to become double-escaped. SafeMarkup - * provides a store for known safe strings and methods to manage them - * throughout the page request. - * - * Strings sanitized by self::checkPlain() and self::escape() are automatically - * marked safe, as are markup strings created from @link theme_render render - * arrays @endlink via drupal_render(). - * - * This class should be limited to internal use only. Module developers should - * instead use the appropriate - * @link sanitization sanitization functions @endlink or the - * @link theme_render theme and render systems @endlink so that the output can - * can be themed, escaped, and altered properly. + * @deprecated Will be removed before Drupal 9.0.0. Use the appropriate + * @link sanitization sanitization functions @endlink or the @link theme_render theme and render systems @endlink + * so that the output can can be themed, escaped, and altered properly. * * @see TwigExtension::escapeFilter() * @see twig_render_template() @@ -35,100 +25,23 @@ use Drupal\Component\Render\MarkupInterface; */ class SafeMarkup { - /** - * The list of safe strings. - * - * Strings in this list are marked as secure for the entire page render, not - * just the code or element that set it. Therefore, only valid HTML should be - * marked as safe (never partial markup). For example, you should never mark - * string such as '<' or '