diff --git a/core/includes/common.inc b/core/includes/common.inc index 1ac5b649247ae845b60cbb552987d7724a01ed46..422c79fd7178db6aead13eab8a37987ba1b5eb18 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -2934,9 +2934,10 @@ function _drupal_bootstrap_code() { // Set the allowed protocols once we have the config available. $allowed_protocols = \Drupal::config('system.filter')->get('protocols'); if (!isset($allowed_protocols)) { - // filter_xss_admin() is called by the installer and update.php, in which - // case the configuration may not exist (yet). Provide a minimal default set - // of allowed protocols for these cases. + // \Drupal\Component\Utility\UrlHelper::filterBadProtocol() is called by the + // installer and update.php, in which case the configuration may not exist + // (yet). Provide a minimal default set of allowed protocols for these + // cases. $allowed_protocols = array('http', 'https'); } UrlHelper::setAllowedProtocols($allowed_protocols); diff --git a/core/includes/errors.inc b/core/includes/errors.inc index 56c276fdfaa247717b98912fc4b3fd5f714aa9c0..1abcdaaca616301dc609fa47f89e770203aa4e87 100644 --- a/core/includes/errors.inc +++ b/core/includes/errors.inc @@ -5,6 +5,7 @@ * Functions for error handling. */ +use Drupal\Component\Utility\Xss; use Drupal\Core\Utility\Error; use Drupal\Component\Utility\String; use Symfony\Component\HttpFoundation\Response; @@ -70,7 +71,7 @@ function _drupal_error_handler_real($error_level, $message, $filename, $line, $c '%type' => isset($types[$error_level]) ? $severity_msg : 'Unknown error', // The standard PHP error handler considers that the error messages // are HTML. We mimick this behavior here. - '!message' => filter_xss_admin($message), + '!message' => Xss::filterAdmin($message), '%function' => $caller['function'], '%file' => $caller['file'], '%line' => $caller['line'], diff --git a/core/includes/form.inc b/core/includes/form.inc index 5b292f53bf88d9c6fd02d689efa1a22b198fe40a..54feee0952db4e274ec727a8e743589f6ed9c3ac 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -2964,7 +2964,7 @@ function theme_form_element_label($variables) { $required = drupal_render($marker); } - $title = filter_xss_admin($element['#title']); + $title = Xss::filterAdmin($element['#title']); $attributes = array(); // Style the label as class option to display inline with the element. @@ -3062,9 +3062,10 @@ function _form_set_attributes(&$element, $class = array()) { * Note: if the batch 'title', 'init_message', 'progress_message', or * 'error_message' could contain any user input, it is the responsibility of * the code calling batch_set() to sanitize them first with a function like - * \Drupal\Component\Utility\String::checkPlain() or filter_xss(). Furthermore, - * if the batch operation returns any user input in the 'results' or 'message' - * keys of $context, it must also sanitize them first. + * \Drupal\Component\Utility\String::checkPlain() or + * \Drupal\Component\Utility\Xss::filter(). Furthermore, if the batch operation + * returns any user input in the 'results' or 'message' keys of $context, it + * must also sanitize them first. * * Sample callback_batch_operation(): * @code diff --git a/core/includes/theme.inc b/core/includes/theme.inc index ed5bd5846b5d0738e3a776c03367a3c23ccba89c..dec14f48ab1d9c2c2120e8945a2fb65155fdad63 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -10,6 +10,7 @@ use Drupal\Component\Utility\String; use Drupal\Component\Utility\UrlHelper; +use Drupal\Component\Utility\Xss; use Drupal\Core\Config\Config; use Drupal\Core\Language\Language; use Drupal\Core\Extension\Extension; @@ -2001,7 +2002,7 @@ function template_preprocess_html(&$variables) { else { $head_title = array('name' => String::checkPlain($site_config->get('name'))); if ($site_config->get('slogan')) { - $head_title['slogan'] = strip_tags(filter_xss_admin($site_config->get('slogan'))); + $head_title['slogan'] = strip_tags(Xss::filterAdmin($site_config->get('slogan'))); } } @@ -2097,7 +2098,7 @@ function template_preprocess_page(&$variables) { $variables['secondary_menu'] = theme_get_setting('features.secondary_menu') ? menu_secondary_menu() : array(); $variables['action_links'] = menu_get_local_actions(); $variables['site_name'] = (theme_get_setting('features.name') ? String::checkPlain($site_config->get('name')) : ''); - $variables['site_slogan'] = (theme_get_setting('features.slogan') ? filter_xss_admin($site_config->get('slogan')) : ''); + $variables['site_slogan'] = (theme_get_setting('features.slogan') ? Xss::filterAdmin($site_config->get('slogan')) : ''); $variables['tabs'] = menu_local_tabs(); // Pass the main menu and secondary menu to the template as render arrays. @@ -2287,7 +2288,7 @@ function template_preprocess_maintenance_page(&$variables) { else { $head_title = array('name' => String::checkPlain($site_name)); if ($site_slogan) { - $head_title['slogan'] = strip_tags(filter_xss_admin($site_slogan)); + $head_title['slogan'] = strip_tags(Xss::filterAdmin($site_slogan)); } } @@ -2309,7 +2310,7 @@ function template_preprocess_maintenance_page(&$variables) { $variables['language'] = $language_interface; $variables['logo'] = theme_get_setting('logo.url'); $variables['site_name'] = (theme_get_setting('features.name') ? String::checkPlain($site_name) : ''); - $variables['site_slogan'] = (theme_get_setting('features.slogan') ? filter_xss_admin($site_slogan) : ''); + $variables['site_slogan'] = (theme_get_setting('features.slogan') ? Xss::filterAdmin($site_slogan) : ''); // Compile a list of classes that are going to be applied to the body element. $variables['attributes']['class'][] = 'maintenance-page'; diff --git a/core/lib/Drupal/Component/Utility/String.php b/core/lib/Drupal/Component/Utility/String.php index cd546ce0a1a401f75a89e0005b1623754b2579dd..9796a5fc018344e5ac7531e81e05fae34f97a2fc 100644 --- a/core/lib/Drupal/Component/Utility/String.php +++ b/core/lib/Drupal/Component/Utility/String.php @@ -79,7 +79,8 @@ public static function decodeEntities($text) { * this for text that has already been prepared for HTML display (for * example, user-supplied text that has already been run through * String::checkPlain() previously, or is expected to contain some limited - * HTML tags and has already been run through filter_xss() previously). + * HTML tags and has already been run through + * \Drupal\Component\Utility\Xss::filter() previously). * * @return mixed * The formatted string, or FALSE if no args specified. diff --git a/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php index 93bfb42f5eb0a23ca6755951ad1837dea8fc5206..7c5db6e771d30549f4f00659f096ee51032dcabb 100644 --- a/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php @@ -7,6 +7,7 @@ namespace Drupal\Core\EventSubscriber; +use Drupal\Component\Utility\Xss; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\KernelEvents; @@ -47,7 +48,7 @@ public function onKernelRequestMaintenance(GetResponseEvent $event) { $maintenance_page = array( '#theme' => 'maintenance_page', '#title' => t('Site under maintenance'), - '#content' => filter_xss_admin( + '#content' => Xss::filterAdmin( t(\Drupal::config('system.maintenance')->get('message'), array('@site' => \Drupal::config('system.site')->get('name'))) ), ); diff --git a/core/lib/Drupal/Core/Utility/Token.php b/core/lib/Drupal/Core/Utility/Token.php index e612de858256b448fc2232f38e3468aacf975641..27a451919f7610766d50bafb09af46d6aa81d23d 100644 --- a/core/lib/Drupal/Core/Utility/Token.php +++ b/core/lib/Drupal/Core/Utility/Token.php @@ -107,9 +107,10 @@ public function __construct(ModuleHandlerInterface $module_handler) { * final text if no replacement value can be generated. * - sanitize: A boolean flag indicating that tokens should be sanitized for * display to a web browser. Defaults to TRUE. Developers who set this - * option to FALSE assume responsibility for running filter_xss(), - * String::checkPlain() or other appropriate scrubbing functions before - * displaying data to users. + * option to FALSE assume responsibility for running + * \Drupal\Component\Utility\Xss::filter(), + * \Drupal\Component\Utility\String::checkPlain() or other appropriate + * scrubbing functions before displaying data to users. * * @return string * Text with tokens replaced. @@ -200,8 +201,9 @@ public function scan($text) { * encoding or truncation to a specific length. * - sanitize: A boolean flag indicating that tokens should be sanitized for * display to a web browser. Developers who set this option to FALSE assume - * responsibility for running filter_xss(), String::checkPlain() or other - * appropriate scrubbing functions before displaying data to users. + * responsibility for running \Drupal\Component\Utility\Xss::filter(), + * \Drupal\Component\Utility\String::checkPlain() or other appropriate + * scrubbing functions before displaying data to users. * * @return array * An associative array of replacement values, keyed by the original 'raw' diff --git a/core/modules/aggregator/aggregator.module b/core/modules/aggregator/aggregator.module index 46957aa9f21da7947455d51ddf8abb9468baf905..47f217384329705c48ae9dc7fed0685e8c9708df 100644 --- a/core/modules/aggregator/aggregator.module +++ b/core/modules/aggregator/aggregator.module @@ -6,6 +6,7 @@ */ use Drupal\aggregator\FeedInterface; +use Drupal\Component\Utility\Xss; /** * Denotes that a feed's items should never expire. @@ -171,7 +172,7 @@ function aggregator_feed_load($fid) { * The filtered content. */ function aggregator_filter_xss($value) { - return filter_xss($value, preg_split('/\s+|<|>/', \Drupal::config('aggregator.settings')->get('items.allowed_html'), -1, PREG_SPLIT_NO_EMPTY)); + return Xss::filter($value, preg_split('/\s+|<|>/', \Drupal::config('aggregator.settings')->get('items.allowed_html'), -1, PREG_SPLIT_NO_EMPTY)); } /** diff --git a/core/modules/block/custom_block/custom_block.pages.inc b/core/modules/block/custom_block/custom_block.pages.inc index 4cca4cc71601314e16e2d4dfe7e9a93924a73252..f24e16b057909526e3da72b23195f8f0b877a6f3 100644 --- a/core/modules/block/custom_block/custom_block.pages.inc +++ b/core/modules/block/custom_block/custom_block.pages.inc @@ -5,6 +5,7 @@ * Provides page callbacks for custom blocks. */ +use Drupal\Component\Utility\Xss; use Drupal\custom_block\Entity\CustomBlockType; use Drupal\custom_block\Entity\CustomBlock; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -26,7 +27,7 @@ function template_preprocess_custom_block_add_list(&$variables) { foreach ($variables['content'] as $type) { $variables['types'][$type->id()] = array( 'link' => \Drupal::l($type->label(), 'custom_block.add_form', array('custom_block_type' => $type->id()), array('query' => $query)), - 'description' => filter_xss_admin($type->description), + 'description' => Xss::filterAdmin($type->description), 'title' => $type->label(), 'localized_options' => array( 'query' => $query, diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListBuilder.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListBuilder.php index 1c09e9f72c30579c31e8f2aa9596077e489cd981..8c84de45bf31da31279b9d67ecd6e373071b5e5c 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListBuilder.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListBuilder.php @@ -7,6 +7,7 @@ namespace Drupal\custom_block; +use Drupal\Component\Utility\Xss; use Drupal\Core\Config\Entity\ConfigEntityListBuilder; use Drupal\Core\Entity\EntityInterface; @@ -44,7 +45,7 @@ public function buildHeader() { */ public function buildRow(EntityInterface $entity) { $row['type'] = \Drupal::linkGenerator()->generateFromUrl($entity->label(), $entity->urlInfo()); - $row['description'] = filter_xss_admin($entity->description); + $row['description'] = Xss::filterAdmin($entity->description); return $row + parent::buildRow($entity); } diff --git a/core/modules/comment/comment.tokens.inc b/core/modules/comment/comment.tokens.inc index b58230a12e4518588908c83988c774cbc03d61c2..f38f98b7a340c5cab8853b84ca28a1def6f4161a 100644 --- a/core/modules/comment/comment.tokens.inc +++ b/core/modules/comment/comment.tokens.inc @@ -5,6 +5,8 @@ * Builds placeholder replacement tokens for comment-related data. */ +use Drupal\Component\Utility\Xss; + /** * Implements hook_token_info(). */ @@ -152,7 +154,7 @@ function comment_tokens($type, $tokens, array $data = array(), array $options = break; case 'title': - $replacements[$original] = $sanitize ? filter_xss($comment->getSubject()) : $comment->getSubject(); + $replacements[$original] = $sanitize ? Xss::filter($comment->getSubject()) : $comment->getSubject(); break; case 'body': @@ -175,13 +177,13 @@ function comment_tokens($type, $tokens, array $data = array(), array $options = case 'name': case 'author': $name = $comment->getAuthorName(); - $replacements[$original] = $sanitize ? filter_xss($name) : $name; + $replacements[$original] = $sanitize ? Xss::filter($name) : $name; break; case 'parent': if ($comment->hasParentComment()) { $parent = $comment->getParentComment(); - $replacements[$original] = $sanitize ? filter_xss($parent->getSubject()) : $parent->getSubject(); + $replacements[$original] = $sanitize ? Xss::filter($parent->getSubject()) : $parent->getSubject(); } break; @@ -196,7 +198,7 @@ function comment_tokens($type, $tokens, array $data = array(), array $options = case 'entity': $entity = $comment->getCommentedEntity(); $title = $entity->label(); - $replacements[$original] = $sanitize ? filter_xss($title) : $title; + $replacements[$original] = $sanitize ? Xss::filter($title) : $title; break; case 'node': @@ -206,7 +208,7 @@ function comment_tokens($type, $tokens, array $data = array(), array $options = if ($comment->getCommentedEntityTypeId() == 'node') { $entity = $comment->getCommentedEntity(); $title = $entity->label(); - $replacements[$original] = $sanitize ? filter_xss($title) : $title; + $replacements[$original] = $sanitize ? Xss::filter($title) : $title; } else { $replacements[$original] = NULL; diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php index bd300fc83877ef04f01964251273f69b8760a160..0d2a4b2ee86a1debf772ce64af505148c9999978 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php @@ -7,6 +7,7 @@ namespace Drupal\comment\Tests; +use Drupal\Component\Utility\Xss; use Drupal\Core\Language\Language; /** @@ -54,11 +55,11 @@ function testCommentTokenReplacement() { $tests = array(); $tests['[comment:cid]'] = $comment->id(); $tests['[comment:hostname]'] = check_plain($comment->getHostname()); - $tests['[comment:name]'] = filter_xss($comment->getAuthorName()); - $tests['[comment:author]'] = filter_xss($comment->getAuthorName()); + $tests['[comment:name]'] = Xss::filter($comment->getAuthorName()); + $tests['[comment:author]'] = Xss::filter($comment->getAuthorName()); $tests['[comment:mail]'] = check_plain($this->admin_user->getEmail()); $tests['[comment:homepage]'] = check_url($comment->getHomepage()); - $tests['[comment:title]'] = filter_xss($comment->getSubject()); + $tests['[comment:title]'] = Xss::filter($comment->getSubject()); $tests['[comment:body]'] = $comment->comment_body->processed; $tests['[comment:url]'] = url('comment/' . $comment->id(), $url_options + array('fragment' => 'comment-' . $comment->id())); $tests['[comment:edit-url]'] = url('comment/' . $comment->id() . '/edit', $url_options); diff --git a/core/modules/dblog/lib/Drupal/dblog/Controller/DbLogController.php b/core/modules/dblog/lib/Drupal/dblog/Controller/DbLogController.php index d891bfe406ef8231611bae12e7cac17fb4969877..72ddf22b13423b65691c7630f701e2bda04c696b 100644 --- a/core/modules/dblog/lib/Drupal/dblog/Controller/DbLogController.php +++ b/core/modules/dblog/lib/Drupal/dblog/Controller/DbLogController.php @@ -181,7 +181,7 @@ public function overview() { } if (isset($dblog->wid)) { // Truncate link_text to 56 chars of message. - $log_text = Unicode::truncate(filter_xss($message, array()), 56, TRUE, TRUE); + $log_text = Unicode::truncate(Xss::filter($message, array()), 56, TRUE, TRUE); $message = $this->l($log_text, 'dblog.event', array('event_id' => $dblog->wid), array('html' => TRUE)); } } diff --git a/core/modules/dblog/lib/Drupal/dblog/Tests/DbLogTest.php b/core/modules/dblog/lib/Drupal/dblog/Tests/DbLogTest.php index 24add00d4259f8d8c3791f856a8c3c73bd1f9729..850b6e14eb827208382950b22a59bd63bb9095b2 100644 --- a/core/modules/dblog/lib/Drupal/dblog/Tests/DbLogTest.php +++ b/core/modules/dblog/lib/Drupal/dblog/Tests/DbLogTest.php @@ -7,6 +7,7 @@ namespace Drupal\dblog\Tests; +use Drupal\Component\Utility\Xss; use Drupal\Core\Language\Language; use Drupal\dblog\Controller\DbLogController; use Drupal\simpletest\WebTestBase; @@ -264,7 +265,7 @@ private function doUser() { $this->assertLogMessage(t('Session closed for %name.', array('%name' => $name)), 'DBLog event was recorded: [logout user]'); // Delete user. $message = t('Deleted user: %name %email.', array('%name' => $name, '%email' => '<' . $user->getEmail() . '>')); - $message_text = truncate_utf8(filter_xss($message, array()), 56, TRUE, TRUE); + $message_text = truncate_utf8(Xss::filter($message, array()), 56, TRUE, TRUE); // Verify that the full message displays on the details page. $link = FALSE; if ($links = $this->xpath('//a[text()="' . html_entity_decode($message_text) . '"]')) { @@ -613,10 +614,10 @@ protected function asText(\SimpleXMLElement $element) { * The message to pass to simpletest. */ protected function assertLogMessage($log_message, $message) { - $message_text = truncate_utf8(filter_xss($log_message, array()), 56, TRUE, TRUE); - // After filter_xss(), HTML entities should be converted to their character - // equivalents because assertLink() uses this string in xpath() to query the - // Document Object Model (DOM). + $message_text = truncate_utf8(Xss::filter($log_message, array()), 56, TRUE, TRUE); + // After \Drupal\Component\Utility\Xss::filter(), HTML entities should be + // converted to their character equivalents because assertLink() uses this + // string in xpath() to query the Document Object Model (DOM). $this->assertLink(html_entity_decode($message_text), 0, $message); } } diff --git a/core/modules/dblog/lib/Drupal/dblog/Tests/Views/ViewsIntegrationTest.php b/core/modules/dblog/lib/Drupal/dblog/Tests/Views/ViewsIntegrationTest.php index 8b2987c289a34d04e6e56f0633244cb7ab017b9a..818cfd3afcf32e6eeaf7e923ab4e43c49baa62fe 100644 --- a/core/modules/dblog/lib/Drupal/dblog/Tests/Views/ViewsIntegrationTest.php +++ b/core/modules/dblog/lib/Drupal/dblog/Tests/Views/ViewsIntegrationTest.php @@ -77,7 +77,8 @@ public function testIntegration() { $entries[] = array( 'message' => '@token1 !token2', 'variables' => array('@token1' => $this->randomName(), '!token2' => $this->randomName()), - // Setup a link with a tag which is filtered by filter_xss_admin. + // Setup a link with a tag which is filtered by + // \Drupal\Component\Utility\Xss::filterAdmin(). 'link' => l('Link', 'node/2', array('html' => TRUE)), ); foreach ($entries as $entry) { diff --git a/core/modules/editor/lib/Drupal/editor/EditorXssFilter/Standard.php b/core/modules/editor/lib/Drupal/editor/EditorXssFilter/Standard.php index 3f9386342c9c042d3e3328e7f7f7dd8e42a40c5e..84197805b99c1be50e7fc4d14c376c31e8ffded6 100644 --- a/core/modules/editor/lib/Drupal/editor/EditorXssFilter/Standard.php +++ b/core/modules/editor/lib/Drupal/editor/EditorXssFilter/Standard.php @@ -25,8 +25,8 @@ public static function filterXss($html, FilterFormatInterface $format, FilterFor // The '; - $slogan_filtered = filter_xss_admin($slogan); + $slogan_filtered = Xss::filterAdmin($slogan); // Activate needed appearance settings. $edit = array( diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeSuggestionsAlterTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeSuggestionsAlterTest.php index a987e1f61e62f43ff44f7b8875b1e71cbe5ec7fb..202ddd2a44bf45d42b6ffda14f58728d7166fea7 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeSuggestionsAlterTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeSuggestionsAlterTest.php @@ -7,6 +7,7 @@ namespace Drupal\system\Tests\Theme; +use Drupal\Component\Utility\Xss; use Drupal\simpletest\WebTestBase; /** @@ -182,7 +183,7 @@ function testExecutionOrder() { 'test_theme_theme_suggestions_alter() executed.', 'test_theme_theme_suggestions_theme_test_suggestions_alter() executed.', ); - $content = preg_replace('/\s+/', ' ', filter_xss($this->content, array())); + $content = preg_replace('/\s+/', ' ', Xss::filter($this->content, array())); $this->assert(strpos($content, implode(' ', $expected)) !== FALSE, 'Suggestion alter hooks executed in the expected order.'); } diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index 84e74c092a91dbbe2dee247d7f2a453f54b75764..52998dee4364e6f2ce2aae8085f585c93f444c3f 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -5,6 +5,7 @@ * Admin page callbacks for the system module. */ +use Drupal\Component\Utility\Xss; use Drupal\Core\Cache\Cache; use Drupal\Core\Extension\Extension; use Drupal\Core\Render\Element; @@ -105,7 +106,7 @@ function template_preprocess_admin_block_content(&$variables) { foreach ($variables['content'] as $key => $item) { $variables['content'][$key]['link'] = l($item['title'], $item['link_path'], $item['localized_options']); if (!$compact && isset($item['description'])) { - $variables['content'][$key]['description'] = filter_xss_admin($item['description']); + $variables['content'][$key]['description'] = Xss::filterAdmin($item['description']); } else { $variables['content'][$key]['description'] = FALSE; diff --git a/core/modules/system/system.tokens.inc b/core/modules/system/system.tokens.inc index 4c27e2cc806a12c4ed540f16b951f13468c89afd..3750ff217ef92033e1859bd487f9a9334e73001d 100644 --- a/core/modules/system/system.tokens.inc +++ b/core/modules/system/system.tokens.inc @@ -7,6 +7,8 @@ * This file handles tokens for the global 'site' and 'date' tokens. */ +use Drupal\Component\Utility\Xss; + /** * Implements hook_token_info(). */ @@ -109,7 +111,7 @@ function system_tokens($type, $tokens, array $data = array(), array $options = a case 'slogan': $slogan = \Drupal::config('system.site')->get('slogan'); - $replacements[$original] = $sanitize ? filter_xss_admin($slogan) : $slogan; + $replacements[$original] = $sanitize ? Xss::filterAdmin($slogan) : $slogan; break; case 'mail': diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php index 18cbdd8af15e24e39ed883c35c16c7264448ee21..a09cbc24e107d5e1db1ed7fe67d099e995ff4946 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php @@ -7,6 +7,7 @@ namespace Drupal\taxonomy\Tests; +use Drupal\Component\Utility\Xss; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Language\Language; use Drupal\Component\Utility\String; @@ -135,7 +136,7 @@ function testTaxonomyTokenReplacement() { $tests = array(); $tests['[vocabulary:vid]'] = $this->vocabulary->id(); $tests['[vocabulary:name]'] = String::checkPlain($this->vocabulary->name); - $tests['[vocabulary:description]'] = filter_xss($this->vocabulary->description); + $tests['[vocabulary:description]'] = Xss::filter($this->vocabulary->description); $tests['[vocabulary:node-count]'] = 1; $tests['[vocabulary:term-count]'] = 2; diff --git a/core/modules/taxonomy/taxonomy.tokens.inc b/core/modules/taxonomy/taxonomy.tokens.inc index ce331da159b2835996edc801172409daa82c8ca1..aa1505c59b2d5ddd8768d3a63fdb0ad561b40904 100644 --- a/core/modules/taxonomy/taxonomy.tokens.inc +++ b/core/modules/taxonomy/taxonomy.tokens.inc @@ -6,6 +6,7 @@ */ use Drupal\Component\Utility\String; +use Drupal\Component\Utility\Xss; /** * Implements hook_token_info(). @@ -164,7 +165,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options = break; case 'description': - $replacements[$original] = $sanitize ? filter_xss($vocabulary->description) : $vocabulary->description; + $replacements[$original] = $sanitize ? Xss::filter($vocabulary->description) : $vocabulary->description; break; case 'term-count': diff --git a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tip/TipPluginText.php b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tip/TipPluginText.php index d8834906aa479cb9a1915373804fc2b6b0e375ef..1858370a25375bb9142238fa8fbb0b7a5e4eb567 100644 --- a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tip/TipPluginText.php +++ b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tip/TipPluginText.php @@ -7,6 +7,7 @@ namespace Drupal\tour\Plugin\tour\tip; +use Drupal\Component\Utility\Xss; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Utility\Token; use Drupal\tour\TipPluginBase; @@ -119,7 +120,7 @@ public function getAttributes() { */ public function getOutput() { $output = '

' . check_plain($this->getLabel()) . '

'; - $output .= '

' . filter_xss_admin($this->token->replace($this->getBody())) . '

'; + $output .= '

' . Xss::filterAdmin($this->token->replace($this->getBody())) . '

'; return array('#markup' => $output); } diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 91a6f25ab7755b58d8ea195af5cfe9ac3b957a1b..a97f6fcf3bf50bd2885a1205a72c6618b76a36ba 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -607,7 +607,7 @@ function user_template_preprocess_default_variables_alter(&$variables) { * * Modules that make any changes to variables like 'name' or 'extra' must ensure * that the final string is safe to include directly in the output by using - * check_plain() or filter_xss(). + * check_plain() or \Drupal\Component\Utility\Xss::filter(). */ function template_preprocess_username(&$variables) { $account = $variables['account'] ?: new AnonymousUserSession(); diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/area/TextCustom.php b/core/modules/views/lib/Drupal/views/Plugin/views/area/TextCustom.php index 6856ccdc9977ad9c33211ff0a1e5ad9744740f27..fcd798cb6b94754a847f1848322bbd85f72ac0de 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/area/TextCustom.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/area/TextCustom.php @@ -53,7 +53,7 @@ public function render($empty = FALSE) { } /** - * Render a text area with filter_xss_admin. + * Render a text area with \Drupal\Component\Utility\Xss::filterAdmin(). */ public function renderTextarea($value) { if ($value) { diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/field/Boolean.php b/core/modules/views/lib/Drupal/views/Plugin/views/field/Boolean.php index 47b1b4ead641772173a69b216259324022b907d6..cf4ef7798597a4f78f4ea9e66e85f58e97cf06fa 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/field/Boolean.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/field/Boolean.php @@ -7,6 +7,7 @@ namespace Drupal\views\Plugin\views\field; +use Drupal\Component\Utility\Xss as UtilityXss; use Drupal\views\ResultRow; use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\display\DisplayPluginBase; @@ -110,7 +111,7 @@ public function render(ResultRow $values) { } if ($this->options['type'] == 'custom') { - return $value ? filter_xss_admin($this->options['type_custom_true']) : filter_xss_admin($this->options['type_custom_false']); + return $value ? UtilityXss::filterAdmin($this->options['type_custom_true']) : UtilityXss::filterAdmin($this->options['type_custom_false']); } elseif (isset($this->formats[$this->options['type']])) { return $value ? $this->formats[$this->options['type']][0] : $this->formats[$this->options['type']][1]; diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php index 08c12cc64f5e30a0308fca1b664bf82d208cbd79..b3c85c1bdea35b4cc800264f292fb372f8762a47 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\Html; use Drupal\Component\Utility\String; +use Drupal\Component\Utility\Xss; use Drupal\views\Plugin\views\HandlerBase; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\ResultRow; @@ -1248,7 +1249,7 @@ public function renderText($alter) { if ($this->options['alter']['more_link'] && strlen($value) < $length) { $tokens = $this->getRenderTokens($alter); $more_link_text = $this->options['alter']['more_link_text'] ? $this->options['alter']['more_link_text'] : t('more'); - $more_link_text = strtr(filter_xss_admin($more_link_text), $tokens); + $more_link_text = strtr(Xss::filterAdmin($more_link_text), $tokens); $more_link_path = $this->options['alter']['more_link_path']; $more_link_path = strip_tags(decode_entities(strtr($more_link_path, $tokens))); @@ -1285,7 +1286,7 @@ public function renderText($alter) { */ protected function renderAltered($alter, $tokens) { // Filter this right away as our substitutions are already sanitized. - $value = filter_xss_admin($alter['text']); + $value = Xss::filterAdmin($alter['text']); $value = strtr($value, $tokens); return $value; @@ -1311,7 +1312,7 @@ protected function renderAsLink($alter, $text, $tokens) { $value = ''; if (!empty($alter['prefix'])) { - $value .= filter_xss_admin(strtr($alter['prefix'], $tokens)); + $value .= Xss::filterAdmin(strtr($alter['prefix'], $tokens)); } $options = array( @@ -1451,7 +1452,7 @@ protected function renderAsLink($alter, $text, $tokens) { $value .= l($text, $path, $options); if (!empty($alter['suffix'])) { - $value .= filter_xss_admin(strtr($alter['suffix'], $tokens)); + $value .= Xss::filterAdmin(strtr($alter['suffix'], $tokens)); } return $value; diff --git a/core/modules/views/lib/Drupal/views/Tests/Plugin/RowEntityTest.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/RowEntityTest.php index 5fa35b88cda13bf43f8f8db5f68307aa272e5df5..0b406f5d7c7c9de51ad7a6ad7695002a0553ca3d 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Plugin/RowEntityTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/RowEntityTest.php @@ -7,6 +7,7 @@ namespace Drupal\views\Tests\Plugin; +use Drupal\Component\Utility\Xss; use Drupal\views\Views; use Drupal\views\Tests\ViewUnitTestBase; @@ -102,7 +103,7 @@ protected function assertText($text, $message = '', $group = 'Other') { if (!$message) { $message = t('Raw "@raw" found', array('@raw' => $text)); } - return $this->assert(strpos(filter_xss($this->content, array()), $text) !== FALSE, $message, $group); + return $this->assert(strpos(Xss::filter($this->content, array()), $text) !== FALSE, $message, $group); } } diff --git a/core/modules/views/tests/modules/views_test_data/lib/Drupal/views_test_data/Plugin/views/display/DisplayTest.php b/core/modules/views/tests/modules/views_test_data/lib/Drupal/views_test_data/Plugin/views/display/DisplayTest.php index a297fc332363b16b4571f4167e1ad0814b2d207b..1447c67ccbfa4f540d9630bfebe825734f0db13c 100644 --- a/core/modules/views/tests/modules/views_test_data/lib/Drupal/views_test_data/Plugin/views/display/DisplayTest.php +++ b/core/modules/views/tests/modules/views_test_data/lib/Drupal/views_test_data/Plugin/views/display/DisplayTest.php @@ -7,6 +7,7 @@ namespace Drupal\views_test_data\Plugin\views\display; +use Drupal\Component\Utility\Xss; use Drupal\views\Plugin\views\display\DisplayPluginBase; /** @@ -124,7 +125,7 @@ public function execute() { $render = $this->view->render(); // Render the test option as the title before the view output. - $render['#prefix'] = '

' . filter_xss_admin($this->options['test_option']) . '

'; + $render['#prefix'] = '

' . Xss::filterAdmin($this->options['test_option']) . '

'; return $render; } diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc index eaf3d860788738a5606a325bc3c8f1e7ed716c41..d01235d2492768000ca8becd1b93f0390d21bc34 100644 --- a/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -62,7 +62,7 @@ function template_preprocess_views_view(&$variables) { // @todo: Figure out whether this belongs into views_ui_preprocess_views_view. // Render title for the admin preview. - $variables['title'] = !empty($view->views_ui_context) ? filter_xss_admin($view->getTitle()) : ''; + $variables['title'] = !empty($view->views_ui_context) ? Xss::filterAdmin($view->getTitle()) : ''; if ($view->display_handler->renderPager()) { $exposed_input = isset($view->exposed_raw_input) ? $view->exposed_raw_input : NULL; @@ -203,7 +203,7 @@ function template_preprocess_views_view_fields(&$variables) { } if (!empty($variables['options']['separator']) && $previous_inline && $object->inline && $object->content) { - $object->separator = filter_xss_admin($variables['options']['separator']); + $object->separator = Xss::filterAdmin($variables['options']['separator']); } $object->class = drupal_clean_css_identifier($id); @@ -453,7 +453,7 @@ function template_preprocess_views_view_summary_unformatted(&$variables) { foreach ($variables['rows'] as $id => $row) { // Only false on first time. if ($count++) { - $variables['rows'][$id]->separator = filter_xss_admin($variables['options']['separator']); + $variables['rows'][$id]->separator = Xss::filterAdmin($variables['options']['separator']); } $variables['rows'][$id]->attributes = array(); $variables['rows'][$id]->link = $argument->summaryName($row); @@ -643,7 +643,7 @@ function template_preprocess_views_view_table(&$variables) { // Place the field into the column, along with an optional separator. if (!empty($column_reference['content'])) { if (!empty($options['info'][$column]['separator'])) { - $column_reference['content'] .= filter_xss_admin($options['info'][$column]['separator']); + $column_reference['content'] .= Xss::filterAdmin($options['info'][$column]['separator']); } } else { diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewEditFormController.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewEditFormController.php index dfd8f6d24b906d7b4bb4596c7fbab5f735022ec1..c6a8aed5f85a99416dc93ea62dc97427323897bb 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewEditFormController.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewEditFormController.php @@ -7,6 +7,7 @@ namespace Drupal\views_ui; +use Drupal\Component\Utility\Xss; use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Ajax\HtmlCommand; use Drupal\Core\Ajax\ReplaceCommand; @@ -1049,7 +1050,7 @@ public function getFormBucket(ViewUI $view, $type, $display) { $field_name = '(' . $relationships[$field['relationship']] . ') ' . $field_name; } - $description = filter_xss_admin($handler->adminSummary()); + $description = Xss::filterAdmin($handler->adminSummary()); $link_text = $field_name . (empty($description) ? '' : " ($description)"); $link_attributes = array('class' => array('views-ajax-link')); if (!empty($field['exclude'])) { diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php index 3d4983746b271c99d655ea3ee099d6e4c92cfe51..ca3d5ecb19a7f9e02ddac2c94e78a47c4c3735a2 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\String; use Drupal\Component\Utility\Timer; +use Drupal\Component\Utility\Xss; use Drupal\views\Views; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\views\ViewExecutable; @@ -691,7 +692,7 @@ public function renderPreview($display_id, $args = array()) { } } if ($show_info) { - $rows['query'][] = array('' . t('Title') . '', filter_xss_admin($this->executable->getTitle())); + $rows['query'][] = array('' . t('Title') . '', Xss::filterAdmin($this->executable->getTitle())); if (isset($path)) { $path = l($path, $path); } diff --git a/core/tests/Drupal/Tests/Component/Utility/XssTest.php b/core/tests/Drupal/Tests/Component/Utility/XssTest.php index 1bdb67c78dd0fba7e55111396fab1a9b130bb4b9..72aade428fa86597f09d9c5e9ce5b5fbd6d0fc50 100644 --- a/core/tests/Drupal/Tests/Component/Utility/XssTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/XssTest.php @@ -119,7 +119,7 @@ public function providerTestFilterXssNormalized() { * @param string $message * The assertion message to display upon failure. * @param array $allowed_tags - * (optional) The allowed HTML tags to be passed to Xss::filter(). + * (optional) The allowed HTML tags to be passed to \Drupal\Component\Utility\Xss::filter(). * * @dataProvider providerTestFilterXssNotNormalized */ @@ -144,7 +144,7 @@ public function testFilterXssNotNormalized($value, $expected, $message, array $a * - The value to expect that's missing after filtering. * - The assertion message. * - (optional) The allowed HTML HTML tags array that should be passed to - * Xss::filter(). + * \Drupal\Component\Utility\Xss::filter(). */ public function providerTestFilterXssNotNormalized() { $cases = array( @@ -437,9 +437,10 @@ public function providerTestFilterXssNotNormalized() { /** * Tests removing disallowed tags and XSS prevention. * - * Xss::filter() has the ability to run in blacklist mode, in which it still - * applies the exact same filtering, with one exception: it no longer works - * with a list of allowed tags, but with a list of disallowed tags. + * \Drupal\Component\Utility\Xss::filter() has the ability to run in blacklist + * mode, in which it still applies the exact same filtering, with one + * exception: it no longer works with a list of allowed tags, but with a list + * of disallowed tags. * * @param string $value * The value to filter. @@ -448,7 +449,7 @@ public function providerTestFilterXssNotNormalized() { * @param string $message * The assertion message to display upon failure. * @param array $disallowed_tags - * (optional) The disallowed HTML tags to be passed to Xss::filter(). + * (optional) The disallowed HTML tags to be passed to \Drupal\Component\Utility\Xss::filter(). * * @dataProvider providerTestBlackListMode */ @@ -467,7 +468,7 @@ public function testBlacklistMode($value, $expected, $message, array $disallowed * - The value to filter. * - The value to expect after filtering. * - The assertion message. - * - (optional) The disallowed HTML tags to be passed to Xss::filter(). + * - (optional) The disallowed HTML tags to be passed to \Drupal\Component\Utility\Xss::filter(). */ public function providerTestBlackListMode() { return array( @@ -537,7 +538,7 @@ public function testQuestionSign() { } /** - * Checks that Xss::filterAdmin() correctly strips unallowed tags. + * Checks that \Drupal\Component\Utility\Xss::filterAdmin() correctly strips unallowed tags. */ public function testFilterXSSAdmin() { $value = Xss::filterAdmin('