Issue #2184653 by amateescu: Rename Drupal\Component\Utility\Url to UrlHelper.

8.0.x
Dries 2014-03-05 15:22:39 -05:00
parent 4638a0048d
commit 1d58c60abc
26 changed files with 97 additions and 97 deletions

View File

@ -6,7 +6,7 @@ use Drupal\Component\Utility\Settings;
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Timer;
use Drupal\Component\Utility\Unicode;
use Drupal\Component\Utility\Url;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\DrupalKernel;
use Drupal\Core\Database\Database;
use Drupal\Core\DependencyInjection\ContainerBuilder;

View File

@ -7,7 +7,7 @@ use Drupal\Component\Utility\Settings;
use Drupal\Component\Utility\SortArray;
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Tags;
use Drupal\Component\Utility\Url;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Language\Language;
@ -428,13 +428,13 @@ function drupal_get_feeds($delimiter = "\n") {
* An array containing query parameters, which can be used for url().
*
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
* Use \Drupal\Component\Utility\Url::filterQueryParameters().
* Use \Drupal\Component\Utility\UrlHelper::filterQueryParameters().
*/
function drupal_get_query_parameters(array $query = NULL, array $exclude = array(), $parent = '') {
if (!isset($query)) {
$query = \Drupal::request()->query->all();
}
return Url::filterQueryParameters($query, $exclude, $parent);
return UrlHelper::filterQueryParameters($query, $exclude, $parent);
}
/**
@ -444,10 +444,10 @@ function drupal_get_query_parameters(array $query = NULL, array $exclude = array
* @ingroup php_wrappers
*
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
* Use \Drupal\Component\Utility\Url::buildQuery().
* Use \Drupal\Component\Utility\UrlHelper::buildQuery().
*/
function drupal_http_build_query(array $query, $parent = '') {
return Url::buildQuery($query, $parent);
return UrlHelper::buildQuery($query, $parent);
}
/**
@ -478,7 +478,7 @@ function drupal_get_destination() {
}
else {
$path = current_path();
$query = Url::buildQuery(Url::filterQueryParameters($query->all()));
$query = UrlHelper::buildQuery(UrlHelper::filterQueryParameters($query->all()));
if ($query != '') {
$path .= '?' . $query;
}
@ -521,10 +521,10 @@ function drupal_get_destination() {
* @ingroup php_wrappers
*
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
* Use \Drupal\Component\Utility\Url::parse().
* Use \Drupal\Component\Utility\UrlHelper::parse().
*/
function drupal_parse_url($url) {
return Url::parse($url);
return UrlHelper::parse($url);
}
/**
@ -539,10 +539,10 @@ function drupal_parse_url($url) {
* The Drupal path to encode.
*
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
* Use \Drupal\Component\Utility\Url::encodePath().
* Use \Drupal\Component\Utility\UrlHelper::encodePath().
*/
function drupal_encode_path($path) {
return Url::encodePath($path);
return UrlHelper::encodePath($path);
}
/**
@ -555,10 +555,10 @@ function drupal_encode_path($path) {
* TRUE if the URL has the same domain and base path.
*
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
* Use \Drupal\Component\Utility\Url::externalIsLocal().
* Use \Drupal\Component\Utility\UrlHelper::externalIsLocal().
*/
function _external_url_is_local($url) {
return Url::externalIsLocal($url, base_path());
return UrlHelper::externalIsLocal($url, base_path());
}
/**
@ -612,13 +612,13 @@ function valid_email_address($mail) {
* @return
* TRUE if the URL is in a valid format.
*
* @see \Drupal\Component\Utility\Url::isValid()
* @see \Drupal\Component\Utility\UrlHelper::isValid()
*
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
* Use \Drupal\Component\Utility\Url::isValid().
* Use \Drupal\Component\Utility\UrlHelper::isValid().
*/
function valid_url($url, $absolute = FALSE) {
return Url::isValid($url, $absolute);
return UrlHelper::isValid($url, $absolute);
}
/**
@ -647,13 +647,13 @@ function valid_url($url, $absolute = FALSE) {
* because Drupal\Core\Template\Attribute expects those values to be
* plain-text strings. To pass a filtered URI to
* Drupal\Core\Template\Attribute, call
* \Drupal\Component\Utility\Url::stripDangerousProtocols() instead.
* \Drupal\Component\Utility\UrlHelper::stripDangerousProtocols() instead.
*
* @see \Drupal\Component\Utility\Url::stripDangerousProtocols()
* @see \Drupal\Component\Utility\UrlHelper::stripDangerousProtocols()
* @see \Drupal\Component\Utility\String::checkPlain()
*/
function check_url($uri) {
return String::checkPlain(Url::stripDangerousProtocols($uri));
return String::checkPlain(UrlHelper::stripDangerousProtocols($uri));
}
/**
@ -719,10 +719,10 @@ function filter_xss($string, $allowed_tags = array('a', 'em', 'strong', 'cite',
* @return string
* Cleaned up and HTML-escaped version of $string.
*
* @see \Drupal\Component\Utility\Url::filterBadProtocol()
* @see \Drupal\Component\Utility\UrlHelper::filterBadProtocol()
*/
function filter_xss_bad_protocol($string) {
return Url::filterBadProtocol($string);
return UrlHelper::filterBadProtocol($string);
}
/**
@ -1107,7 +1107,7 @@ function url($path = NULL, array $options = array()) {
* Boolean TRUE or FALSE, where TRUE indicates an external path.
*/
function url_is_external($path) {
return Url::isExternal($path);
return UrlHelper::isExternal($path);
}
/**
@ -3191,7 +3191,7 @@ function _drupal_bootstrap_code() {
// of allowed protocols for these cases.
$allowed_protocols = array('http', 'https');
}
Url::setAllowedProtocols($allowed_protocols);
UrlHelper::setAllowedProtocols($allowed_protocols);
}
/**

View File

@ -8,7 +8,7 @@
use Drupal\Component\Utility\NestedArray;
use Drupal\Component\Utility\Number;
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Url;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Database\Database;
use Drupal\Core\Language\Language;
use Drupal\Core\Template\Attribute;
@ -2691,7 +2691,7 @@ function form_pre_render_color($element) {
function theme_form($variables) {
$element = $variables['element'];
if (isset($element['#action'])) {
$element['#attributes']['action'] = Url::stripDangerousProtocols($element['#action']);
$element['#attributes']['action'] = UrlHelper::stripDangerousProtocols($element['#action']);
}
element_set_attributes($element, array('method', 'id'));
if (empty($element['#attributes']['accept-charset'])) {

View File

@ -6,7 +6,7 @@
*/
use Drupal\Core\Template\Attribute;
use Drupal\Component\Utility\Url;
use Drupal\Component\Utility\UrlHelper;
/**
* Returns the current page being requested for display within a pager.
@ -148,7 +148,7 @@ function pager_default_initialize($total, $limit, $element = 0) {
function pager_get_query_parameters() {
$query = &drupal_static(__FUNCTION__);
if (!isset($query)) {
$query = Url::filterQueryParameters(\Drupal::request()->query->all(), array('page'));
$query = UrlHelper::filterQueryParameters(\Drupal::request()->query->all(), array('page'));
}
return $query;
}

View File

@ -5,7 +5,7 @@
* Functions to handle paths in Drupal.
*/
use Drupal\Component\Utility\Url;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\ParamConverter\ParamNotConvertedException;
use Drupal\Core\Routing\RequestHelper;
@ -193,7 +193,7 @@ function path_get_admin_paths() {
*/
function drupal_valid_path($path) {
// External URLs and the front page are always valid.
if ($path == '<front>' || Url::isExternal($path)) {
if ($path == '<front>' || UrlHelper::isExternal($path)) {
return TRUE;
}

View File

@ -3,7 +3,7 @@
use Drupal\Core\Database\Connection;
use Drupal\Core\Database\Query\SelectExtender;
use Drupal\Core\Database\Query\SelectInterface;
use Drupal\Component\Utility\Url;
use Drupal\Component\Utility\UrlHelper;
/**
* @file
@ -106,7 +106,7 @@ function tablesort_cell($cell, $header, $ts, $i) {
* page request except for those pertaining to table sorting.
*/
function tablesort_get_query_parameters() {
return Url::filterQueryParameters(\Drupal::request()->query->all(), array('sort', 'order'));
return UrlHelper::filterQueryParameters(\Drupal::request()->query->all(), array('sort', 'order'));
}
/**

View File

@ -9,7 +9,7 @@
*/
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Url;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Config\Config;
use Drupal\Core\Language\Language;
use Drupal\Core\Extension\Extension;
@ -2026,7 +2026,7 @@ function template_preprocess_html(&$variables) {
$type = theme_get_setting('favicon.mimetype');
$build['#attached']['drupal_add_html_head_link'][][] = array(
'rel' => 'shortcut icon',
'href' => Url::stripDangerousProtocols($favicon),
'href' => UrlHelper::stripDangerousProtocols($favicon),
'type' => $type,
);
drupal_render($build);
@ -2315,7 +2315,7 @@ function template_preprocess_maintenance_page(&$variables) {
$type = theme_get_setting('favicon.mimetype');
$build['#attached']['drupal_add_html_head_link'][][] = array(
'rel' => 'shortcut icon',
'href' => Url::stripDangerousProtocols($favicon),
'href' => UrlHelper::stripDangerousProtocols($favicon),
'type' => $type,
);
drupal_render($build);

View File

@ -2,17 +2,15 @@
/**
* @file
* Contains \Drupal\Component\Utility\Url.
* Contains \Drupal\Component\Utility\UrlHelper.
*/
namespace Drupal\Component\Utility;
/**
* Helper class URL based methods.
*
* @todo Rename to UrlHelper in https://drupal.org/node/2184653.
*/
class Url {
class UrlHelper {
/**
* The list of allowed protocols.
@ -121,7 +119,7 @@ class Url {
* The returned array contains a 'path' that may be passed separately to url().
* For example:
* @code
* $options = Url::parse(\Drupal::request()->query->get('destination'));
* $options = UrlHelper::parse(\Drupal::request()->query->get('destination'));
* $my_url = url($options['path'], $options);
* $my_link = l('Example link', $options['path'], $options);
* @endcode

View File

@ -251,7 +251,7 @@ class Xss {
case 2:
// Attribute value, a URL after href= for instance.
if (preg_match('/^"([^"]*)"(\s+|$)/', $attributes, $match)) {
$thisval = Url::filterBadProtocol($match[1]);
$thisval = UrlHelper::filterBadProtocol($match[1]);
if (!$skip) {
$attributes_array[] = "$attribute_name=\"$thisval\"";
@ -263,7 +263,7 @@ class Xss {
}
if (preg_match("/^'([^']*)'(\s+|$)/", $attributes, $match)) {
$thisval = Url::filterBadProtocol($match[1]);
$thisval = UrlHelper::filterBadProtocol($match[1]);
if (!$skip) {
$attributes_array[] = "$attribute_name='$thisval'";
@ -274,7 +274,7 @@ class Xss {
}
if (preg_match("%^([^\s\"']+)(\s+|$)%", $attributes, $match)) {
$thisval = Url::filterBadProtocol($match[1]);
$thisval = UrlHelper::filterBadProtocol($match[1]);
if (!$skip) {
$attributes_array[] = "$attribute_name=\"$thisval\"";

View File

@ -8,7 +8,7 @@
namespace Drupal\Core\Form;
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Url as UrlHelper;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\Request;

View File

@ -10,7 +10,7 @@ namespace Drupal\Core\Form;
use Drupal\Component\Utility\Crypt;
use Drupal\Component\Utility\NestedArray;
use Drupal\Component\Utility\Unicode;
use Drupal\Component\Utility\Url as UrlHelper;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Access\CsrfTokenGenerator;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\HttpKernel;

View File

@ -16,7 +16,7 @@ use Symfony\Component\Routing\Exception\RouteNotFoundException;
use Symfony\Cmf\Component\Routing\ProviderBasedGenerator;
use Drupal\Component\Utility\Settings;
use Drupal\Component\Utility\Url;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\PathProcessor\OutboundPathProcessorInterface;
use Drupal\Core\RouteProcessor\OutboundRouteProcessorInterface;
@ -98,7 +98,7 @@ class UrlGenerator extends ProviderBasedGenerator implements UrlGeneratorInterfa
$this->routeProcessor = $route_processor;
$this->mixedModeSessions = $settings->get('mixed_mode_sessions', FALSE);
$allowed_protocols = $config->get('system.filter')->get('protocols') ?: array('http', 'https');
Url::setAllowedProtocols($allowed_protocols);
UrlHelper::setAllowedProtocols($allowed_protocols);
}
/**
@ -243,12 +243,13 @@ class UrlGenerator extends ProviderBasedGenerator implements UrlGeneratorInterfa
if (!isset($options['external'])) {
// Return an external link if $path contains an allowed absolute URL. Only
// call the slow \Drupal\Component\Utility\Url::stripDangerousProtocols()
// if $path contains a ':' before any / ? or #. Note: we could use
// call the slow
// \Drupal\Component\Utility\UrlHelper::stripDangerousProtocols() if $path
// contains a ':' before any / ? or #. Note: we could use
// url_is_external($path) here, but that would require another function
// call, and performance inside url() is critical.
$colonpos = strpos($path, ':');
$options['external'] = ($colonpos !== FALSE && !preg_match('![/?#]!', substr($path, 0, $colonpos)) && Url::stripDangerousProtocols($path) == $path);
$options['external'] = ($colonpos !== FALSE && !preg_match('![/?#]!', substr($path, 0, $colonpos)) && UrlHelper::stripDangerousProtocols($path) == $path);
}
if (isset($options['fragment']) && $options['fragment'] !== '') {
@ -266,7 +267,7 @@ class UrlGenerator extends ProviderBasedGenerator implements UrlGeneratorInterfa
}
// Append the query.
if ($options['query']) {
$path .= (strpos($path, '?') !== FALSE ? '&' : '?') . Url::buildQuery($options['query']);
$path .= (strpos($path, '?') !== FALSE ? '&' : '?') . UrlHelper::buildQuery($options['query']);
}
if (isset($options['https']) && $this->mixedModeSessions) {
if ($options['https'] === TRUE) {
@ -309,7 +310,7 @@ class UrlGenerator extends ProviderBasedGenerator implements UrlGeneratorInterfa
$prefix = empty($path) ? rtrim($options['prefix'], '/') : $options['prefix'];
$path = str_replace('%2F', '/', rawurlencode($prefix . $path));
$query = $options['query'] ? ('?' . Url::buildQuery($options['query'])) : '';
$query = $options['query'] ? ('?' . UrlHelper::buildQuery($options['query'])) : '';
return $base . $options['script'] . $path . $query . $options['fragment'];
}

View File

@ -7,7 +7,7 @@
namespace Drupal\Core;
use Drupal\Component\Utility\Url as UrlHelper;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\DependencyInjection\DependencySerialization;
use Drupal\Core\Routing\MatchingRouteNotFoundException;
use Drupal\Core\Routing\UrlGeneratorInterface;

View File

@ -8,7 +8,7 @@
namespace Drupal\aggregator\Form;
use Drupal\aggregator\FeedStorageControllerInterface;
use Drupal\Component\Utility\Url;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Form\FormBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
@ -158,7 +158,7 @@ class OpmlFeedAdd extends FormBase {
// @todo Move this functionality to a processor.
foreach ($feeds as $feed) {
// Ensure URL is valid.
if (!Url::isValid($feed['url'], TRUE)) {
if (!UrlHelper::isValid($feed['url'], TRUE)) {
drupal_set_message($this->t('The URL %url is invalid.', array('%url' => $feed['url'])), 'warning');
continue;
}

View File

@ -5,7 +5,7 @@
* Adds contextual links to perform actions related to elements on a page.
*/
use Drupal\Component\Utility\Url;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Template\Attribute;
/**
@ -267,8 +267,8 @@ function contextual_contextual_links_view_alter(&$element, $items) {
function _contextual_links_to_id($contextual_links) {
$ids = array();
foreach ($contextual_links as $group => $args) {
$route_parameters = Url::buildQuery($args['route_parameters']);
$metadata = Url::buildQuery((isset($args['metadata'])) ? $args['metadata'] : array());
$route_parameters = UrlHelper::buildQuery($args['route_parameters']);
$metadata = UrlHelper::buildQuery((isset($args['metadata'])) ? $args['metadata'] : array());
$ids[] = "{$group}:{$route_parameters}:{$metadata}";
}
return implode('|', $ids);

View File

@ -7,7 +7,7 @@
namespace Drupal\field_ui;
use Drupal\Component\Utility\Url;
use Drupal\Component\Utility\UrlHelper;
/**
* Static service container wrapper for Field UI.
@ -59,7 +59,7 @@ class FieldUI {
$next_destination['options']['query']['destinations'] = $destinations;
}
else {
$options = Url::parse($next_destination);
$options = UrlHelper::parse($next_destination);
if ($destinations) {
$options['query']['destinations'] = $destinations;
}

View File

@ -14,7 +14,7 @@ use Drupal\image\ImageEffectBag;
use Drupal\image\ImageEffectInterface;
use Drupal\image\ImageStyleInterface;
use Drupal\Component\Utility\Crypt;
use Drupal\Component\Utility\Url;
use Drupal\Component\Utility\UrlHelper;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
/**
@ -231,7 +231,7 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface, Entity
$file_url = file_create_url($uri);
// Append the query string with the token, if necessary.
if ($token_query) {
$file_url .= (strpos($file_url, '?') !== FALSE ? '&' : '?') . Url::buildQuery($token_query);
$file_url .= (strpos($file_url, '?') !== FALSE ? '&' : '?') . UrlHelper::buildQuery($token_query);
}
return $file_url;

View File

@ -7,7 +7,7 @@
namespace Drupal\link\Plugin\Field\FieldFormatter;
use Drupal\Component\Utility\Url;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Component\Utility\String;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldItemInterface;
@ -170,7 +170,7 @@ class LinkFormatter extends FormatterBase {
$settings = $this->getSettings();
// Split out the link into the parts required for url(): path and options.
$parsed_url = Url::parse($item->url);
$parsed_url = UrlHelper::parse($item->url);
$result = array(
'path' => $parsed_url['path'],
'options' => array(

View File

@ -8,7 +8,7 @@
namespace Drupal\system\Tests\Common;
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Url;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Language\Language;
use Drupal\Core\Template\Attribute;
@ -180,7 +180,7 @@ class RenderElementTypesTest extends DrupalUnitTestBase {
// Add favicon.
$favicon = theme_get_setting('favicon.url');
$type = theme_get_setting('favicon.mimetype');
drupal_add_html_head_link(array('rel' => 'shortcut icon', 'href' => Url::stripDangerousProtocols($favicon), 'type' => $type));
drupal_add_html_head_link(array('rel' => 'shortcut icon', 'href' => UrlHelper::stripDangerousProtocols($favicon), 'type' => $type));
// Build CSS links.
drupal_static_reset('_drupal_add_css');

View File

@ -7,7 +7,7 @@
namespace Drupal\system\Tests\Common;
use Drupal\Component\Utility\Url;
use Drupal\Component\Utility\UrlHelper;
use Drupal\simpletest\DrupalUnitTestBase;
/**
@ -54,12 +54,13 @@ class XssUnitTest extends DrupalUnitTestBase {
*/
function testBadProtocolStripping() {
// Ensure that check_url() strips out harmful protocols, and encodes for
// HTML. Ensure \Drupal\Component\Utility\Url::stripDangerousProtocols() can
// HTML.
// Ensure \Drupal\Component\Utility\UrlHelper::stripDangerousProtocols() can
// be used to return a plain-text string stripped of harmful protocols.
$url = 'javascript:http://www.example.com/?x=1&y=2';
$expected_plain = 'http://www.example.com/?x=1&y=2';
$expected_html = 'http://www.example.com/?x=1&amp;y=2';
$this->assertIdentical(check_url($url), $expected_html, 'check_url() filters a URL and encodes it for HTML.');
$this->assertIdentical(Url::stripDangerousProtocols($url), $expected_plain, '\Drupal\Component\Utility\Url::stripDangerousProtocols() filters a URL and returns plain text.');
$this->assertIdentical(UrlHelper::stripDangerousProtocols($url), $expected_plain, '\Drupal\Component\Utility\Url::stripDangerousProtocols() filters a URL and returns plain text.');
}
}

View File

@ -7,7 +7,7 @@
namespace Drupal\views\Controller;
use Drupal\Component\Utility\Url;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Ajax\ReplaceCommand;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityStorageControllerInterface;
@ -115,7 +115,7 @@ class ViewAjaxController implements ContainerInjectionInterface {
// Overwrite the destination.
// @see drupal_get_destination()
$origin_destination = $path;
$query = Url::buildQuery($request->query->all());
$query = UrlHelper::buildQuery($request->query->all());
if ($query != '') {
$origin_destination .= '?' . $query;
}

View File

@ -7,7 +7,7 @@
namespace Drupal\views\Form;
use Drupal\Component\Utility\Url;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Controller\ControllerResolverInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\DependencyInjection\DependencySerialization;
@ -126,7 +126,7 @@ class ViewsForm extends DependencySerialization implements FormInterface, Contai
$form = array();
$query = $this->request->query->all();
$query = Url::filterQueryParameters($query, array(), '');
$query = UrlHelper::filterQueryParameters($query, array(), '');
$form['#action'] = $this->urlGenerator->generateFromPath($view->getUrl(), array('query' => $query));
// Tell the preprocessor whether it should hide the header, footer, pager...

View File

@ -9,7 +9,7 @@ namespace Drupal\views\Plugin\views;
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Unicode;
use Drupal\Component\Utility\Url;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Session\AccountInterface;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
@ -230,7 +230,7 @@ abstract class HandlerBase extends PluginBase {
$value = Xss::filterAdmin($value);
break;
case 'url':
$value = String::checkPlain(Url::stripDangerousProtocols($value));
$value = String::checkPlain(UrlHelper::stripDangerousProtocols($value));
break;
default:
$value = String::checkPlain($value);

View File

@ -8,7 +8,7 @@
namespace Drupal\Tests\Component\Utility;
use Drupal\Component\Utility\Url;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Component\Utility\String;
use Drupal\Tests\UnitTestCase;
@ -21,8 +21,8 @@ class UrlTest extends UnitTestCase {
public static function getInfo() {
return array(
'name' => t('Url Tests'),
'description' => t('Tests the Url utility class.'),
'name' => t('UrlHelper Tests'),
'description' => t('Tests the UrlHelper utility class.'),
'group' => t('Path API'),
);
}
@ -43,7 +43,7 @@ class UrlTest extends UnitTestCase {
}
/**
* Tests Url::buildQuery().
* Tests UrlHelper::buildQuery().
*
* @param array $query
* The array of query parameters.
@ -55,7 +55,7 @@ class UrlTest extends UnitTestCase {
* @dataProvider providerTestBuildQuery
*/
public function testBuildQuery($query, $expected, $message) {
$this->assertEquals(Url::buildQuery($query), $expected, $message);
$this->assertEquals(UrlHelper::buildQuery($query), $expected, $message);
}
/**
@ -100,7 +100,7 @@ class UrlTest extends UnitTestCase {
*/
public function testValidAbsolute($url, $scheme) {
$test_url = $scheme . '://' . $url;
$valid_url = Url::isValid($test_url, TRUE);
$valid_url = UrlHelper::isValid($test_url, TRUE);
$this->assertTrue($valid_url, String::format('@url is a valid URL.', array('@url' => $test_url)));
}
@ -130,7 +130,7 @@ class UrlTest extends UnitTestCase {
*/
public function testInvalidAbsolute($url, $scheme) {
$test_url = $scheme . '://' . $url;
$valid_url = Url::isValid($test_url, TRUE);
$valid_url = UrlHelper::isValid($test_url, TRUE);
$this->assertFalse($valid_url, String::format('@url is NOT a valid URL.', array('@url' => $test_url)));
}
@ -163,7 +163,7 @@ class UrlTest extends UnitTestCase {
*/
public function testValidRelative($url, $prefix) {
$test_url = $prefix . $url;
$valid_url = Url::isValid($test_url);
$valid_url = UrlHelper::isValid($test_url);
$this->assertTrue($valid_url, String::format('@url is a valid URL.', array('@url' => $test_url)));
}
@ -193,7 +193,7 @@ class UrlTest extends UnitTestCase {
*/
public function testInvalidRelative($url, $prefix) {
$test_url = $prefix . $url;
$valid_url = Url::isValid($test_url);
$valid_url = UrlHelper::isValid($test_url);
$this->assertFalse($valid_url, String::format('@url is NOT a valid URL.', array('@url' => $test_url)));
}
@ -213,7 +213,7 @@ class UrlTest extends UnitTestCase {
* @see \Drupal\Component\Utility\Url::filterQueryParameters().
*/
public function testFilterQueryParameters($query, $exclude, $expected) {
$filtered = Url::filterQueryParameters($query, $exclude);
$filtered = UrlHelper::filterQueryParameters($query, $exclude);
$this->assertEquals($expected, $filtered, 'The query was not properly filtered.');
}
@ -252,7 +252,7 @@ class UrlTest extends UnitTestCase {
* @see \Drupal\Component\Utility\Url::parse()
*/
public function testParse($url, $expected) {
$parsed = Url::parse($url);
$parsed = UrlHelper::parse($url);
$this->assertEquals($expected, $parsed, 'The url was not properly parsed.');
}
@ -307,7 +307,7 @@ class UrlTest extends UnitTestCase {
* @dataProvider providerTestEncodePath
*/
public function testEncodePath($path, $expected) {
$encoded = Url::encodePath($path);
$encoded = UrlHelper::encodePath($path);
$this->assertEquals($expected, $encoded);
}
@ -336,7 +336,7 @@ class UrlTest extends UnitTestCase {
* @dataProvider providerTestIsExternal
*/
public function testIsExternal($path, $expected) {
$isExternal = Url::isExternal($path);
$isExternal = UrlHelper::isExternal($path);
$this->assertEquals($expected, $isExternal);
}
@ -366,8 +366,8 @@ class UrlTest extends UnitTestCase {
* @dataProvider providerTestFilterBadProtocol
*/
public function testFilterBadProtocol($uri, $expected, $protocols) {
Url::setAllowedProtocols($protocols);
$filtered = Url::filterBadProtocol($uri);
UrlHelper::setAllowedProtocols($protocols);
$filtered = UrlHelper::filterBadProtocol($uri);
$this->assertEquals($expected, $filtered);
}
@ -403,8 +403,8 @@ class UrlTest extends UnitTestCase {
* @dataProvider providerTestStripDangerousProtocols
*/
public function testStripDangerousProtocols($uri, $expected, $protocols) {
Url::setAllowedProtocols($protocols);
$stripped = Url::stripDangerousProtocols($uri);
UrlHelper::setAllowedProtocols($protocols);
$stripped = UrlHelper::stripDangerousProtocols($uri);
$this->assertEquals($expected, $stripped);
}

View File

@ -8,7 +8,7 @@
namespace Drupal\Tests\Component\Utility;
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Url;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Component\Utility\Xss;
use Drupal\Tests\UnitTestCase;
@ -53,7 +53,7 @@ class XssTest extends UnitTestCase {
'webcal',
'rtsp',
);
Url::setAllowedProtocols($allowed_protocols);
UrlHelper::setAllowedProtocols($allowed_protocols);
}
/**

View File

@ -7,7 +7,7 @@
namespace Drupal\Tests\Core\EventSubscriber;
use Drupal\Component\Utility\Url;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\EventSubscriber\ExceptionListener;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
@ -90,7 +90,7 @@ class ExceptionListenerTest extends UnitTestCase {
$this->exceptionListener->onKernelException($event);
$response = $event->getResponse();
$this->assertEquals('POST name=druplicon&pass=12345', $response->getContent() . " " . Url::buildQuery($request->request->all()));
$this->assertEquals('POST name=druplicon&pass=12345', $response->getContent() . " " . UrlHelper::buildQuery($request->request->all()));
}
/**
@ -100,14 +100,14 @@ class ExceptionListenerTest extends UnitTestCase {
$request = Request::create('/test', 'GET', array('name' => 'druplicon', 'pass' => '12345'));
$this->kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) {
return new Response($request->getMethod() . ' ' . Url::buildQuery($request->query->all()));
return new Response($request->getMethod() . ' ' . UrlHelper::buildQuery($request->query->all()));
}));
$event = new GetResponseForExceptionEvent($this->kernel, $request, 'foo', new \Exception('foo'));
$this->exceptionListener->onKernelException($event);
$response = $event->getResponse();
$this->assertEquals('GET name=druplicon&pass=12345 ', $response->getContent() . " " . Url::buildQuery($request->request->all()));
$this->assertEquals('GET name=druplicon&pass=12345 ', $response->getContent() . " " . UrlHelper::buildQuery($request->request->all()));
}
}