Commit e69cd767 authored by webchick's avatar webchick

Issue #2416763 by xjm, Wim Leers, effulgentsia: Convert Url::fromUri() base:// scheme to base:

parent 089a68f4
......@@ -499,9 +499,9 @@ function _format_date_callback(array $matches = NULL, $new_langcode = NULL) {
* non-controller or sub-domain URIs such as core/install.php. Note that
* \Drupal\Core\Url::fromUri() expects a valid URI including the scheme. URIs
* from the same sub-domain that are not handled by Drupal controllers should
* be prepended with base://. For example:
* use the base: scheme. For example:
* @code
* $installer_url = \Drupal\Core\Url::fromUri('base://core/install.php')->toString();
* $installer_url = \Drupal\Core\Url::fromUri('base:core/install.php')->toString();
* $external_url = \Drupal\Core\Url::fromUri('http://example.com', ['query' => ['foo' => 'bar']])->toString();
* $internal_url = \Drupal\Core\Url::fromRoute('system.admin')->toString();
* @endcode
......@@ -604,9 +604,9 @@ function drupal_http_header_attributes(array $attributes = array()) {
* core/install.php use \Drupal\Core\Url::fromUri(). Note that
* \Drupal\Core\Url::fromUri() expects a valid URI including the scheme. URIs
* from the same sub-domain that are not handled by Drupal controllers should
* be prepended with base://. For example:
* be prepended with base:. For example:
* @code
* $installer_url = \Drupal\Core\Url::fromUri('base://core/install.php')->toString();
* $installer_url = \Drupal\Core\Url::fromUri('base:core/install.php')->toString();
* $installer_link = \Drupal::l($text, $installer_url);
* $external_url = \Drupal\Core\Url::fromUri('http://example.com', ['query' => ['foo' => 'bar']])->toString();
* $external_link = \Drupal::l($text, $external_url);
......
......@@ -584,7 +584,7 @@ function install_run_task($task, &$install_state) {
// Otherwise, the batch will complete.
// Disable the default script for the URL and clone the object, as
// batch_process() will add additional options to the batch URL.
$url = Url::fromUri('base://install.php', ['query' => $install_state['parameters'], 'script' => '']);
$url = Url::fromUri('base:install.php', ['query' => $install_state['parameters'], 'script' => '']);
$response = batch_process($url, clone $url);
if ($response instanceof Response) {
// Save $_SESSION data from batch.
......
......@@ -476,7 +476,7 @@ public static function urlGenerator() {
* the \Drupal\Core\Url object. See \Drupal\Core\Url::fromRoute() for
* detailed documentation. For non-routed local URIs relative to
* the base path (like robots.txt) use Url::fromUri()->toString() with the
* base:// scheme.
* base: scheme.
*
* @param string $route_name
* The name of the route.
......
......@@ -36,7 +36,7 @@ public static function buildCancelLink(ConfirmFormInterface $form, Request $requ
$options = UrlHelper::parse($query->get('destination'));
// @todo Use Url::fromPath() once https://www.drupal.org/node/2351379 is
// resolved.
$url = Url::fromUri('base://' . $options['path'], $options);
$url = Url::fromUri('base:' . $options['path'], $options);
}
// Check for a route-based cancel link.
else {
......
......@@ -139,7 +139,7 @@ public function __construct($route_name, $route_parameters = array(), $options =
*
* This method is for URLs that have Drupal routes (that is, most pages
* generated by Drupal). For non-routed local URIs relative to the base
* path (like robots.txt) use Url::fromUri() with the base:// scheme.
* path (like robots.txt) use Url::fromUri() with the base: scheme.
*
* @param string $route_name
* The name of the route
......@@ -193,7 +193,7 @@ public static function fromRouteMatch(RouteMatchInterface $route_match) {
*
* This method is for generating URLs for URIs that:
* - do not have Drupal routes: both external URLs and unrouted local URIs
* like base://robots.txt
* like base:robots.txt
* - do have a Drupal route but have a custom scheme to simplify linking.
* Currently, there is only the entity: scheme (This allows URIs of the
* form entity:{entity_type}/{entity_id}. For example: entity:node/1
......@@ -204,7 +204,7 @@ public static function fromRouteMatch(RouteMatchInterface $route_match) {
*
* @param string $uri
* The URI of the resource including the scheme. For Drupal paths that are
* not handled by the routing system, use base:// for the scheme. For entity
* not handled by the routing system, use base: for the scheme. For entity
* URLs you may use entity:{entity_type}/{entity_id} URIs.
* @param array $options
* (optional) An associative array of additional URL options, with the
......@@ -233,15 +233,18 @@ public static function fromRouteMatch(RouteMatchInterface $route_match) {
*/
public static function fromUri($uri, $options = array()) {
if (!($scheme = parse_url($uri, PHP_URL_SCHEME))) {
throw new \InvalidArgumentException(String::format('The URI "@uri" is invalid. You must use a valid URI scheme. Use base:// for a path, e.g., to a Drupal file that needs the base path. Do not use this for internal paths controlled by Drupal.', ['@uri' => $uri]));
throw new \InvalidArgumentException(String::format('The URI "@uri" is invalid. You must use a valid URI scheme. Use base: for a path, e.g., to a Drupal file that needs the base path. Do not use this for internal paths controlled by Drupal.', ['@uri' => $uri]));
}
// Special case entity: URIs. Map these to the canonical entity route.
if ($scheme === 'entity') {
return static::fromEntityUri($uri);
}
$url = new static($uri, array(), $options);
if ($scheme !== 'base') {
$url->external = TRUE;
$url->setOption('external', TRUE);
}
$url->setUnrouted();
return $url;
......@@ -313,11 +316,6 @@ protected function setUnrouted() {
// Set empty route name and parameters.
$this->routeName = NULL;
$this->routeParameters = array();
// @todo Add a method for the check below in
// https://www.drupal.org/node/2346859.
if ($this->external = strpos($this->uri, 'base://') !== 0) {
$this->options['external'] = TRUE;
}
}
/**
......
......@@ -61,14 +61,14 @@ public function assemble($uri, array $options = []) {
// Note that UrlHelper::isExternal will return FALSE if the $uri has a
// disallowed protocol. This is later made safe since we always add at
// least a leading slash.
if (strpos($uri, 'base://') === 0) {
if (parse_url($uri, PHP_URL_SCHEME) === 'base') {
return $this->buildLocalUrl($uri, $options);
}
elseif (UrlHelper::isExternal($uri)) {
// UrlHelper::isExternal() only returns true for safe protocols.
return $this->buildExternalUrl($uri, $options);
}
throw new \InvalidArgumentException(String::format('The URI "@uri" is invalid. You must use a valid URI scheme. Use base:// for a path, e.g., to a Drupal file that needs the base path. Do not use this for internal paths controlled by Drupal.', ['@uri' => $uri]));
throw new \InvalidArgumentException(String::format('The URI "@uri" is invalid. You must use a valid URI scheme. Use base: for a path, e.g., to a Drupal file that needs the base path. Do not use this for internal paths controlled by Drupal.', ['@uri' => $uri]));
}
/**
......@@ -108,8 +108,10 @@ protected function buildLocalUrl($uri, array $options = []) {
$this->addOptionDefaults($options);
$request = $this->requestStack->getCurrentRequest();
// Remove the base:// scheme.
$uri = substr($uri, 7);
// Remove the base: scheme.
// @todo Consider using a class constant for this in
// https://www.drupal.org/node/2417459
$uri = substr($uri, 5);
// Allow (outbound) path processing, if needed. A valid use case is the path
// alias overview form:
......
......@@ -18,11 +18,11 @@ interface UnroutedUrlAssemblerInterface {
* domain-local URIs and external URLs.
*
* @param string $uri
* A local URI or an external URL being linked to, such as "base://foo"
* A local URI or an external URL being linked to, such as "base:foo"
* or "http://example.com/foo".
* - If you provide a full URL, it will be considered an external URL as
* long as it has an allowed protocol.
* - If you provide only a local URI (e.g. "base://foo"), it will be
* - If you provide only a local URI (e.g. "base:foo"), it will be
* considered a path local to Drupal, but not handled by the routing
* system. The base path (the subdirectory where the front controller
* is found) will be added to the path. Additional query arguments for
......
......@@ -255,11 +255,11 @@ public function eventDetails($event_id) {
),
array(
array('data' => $this->t('Location'), 'header' => TRUE),
$this->l($dblog->location, $dblog->location ? Url::fromUri('base://' . $dblog->location) : Url::fromRoute('<none>')),
$this->l($dblog->location, $dblog->location ? Url::fromUri('base:' . $dblog->location) : Url::fromRoute('<none>')),
),
array(
array('data' => $this->t('Referrer'), 'header' => TRUE),
$this->l($dblog->referer, $dblog->referer ? Url::fromUri('base://' . $dblog->referer) : Url::fromRoute('<none>')),
$this->l($dblog->referer, $dblog->referer ? Url::fromUri('base:' . $dblog->referer) : Url::fromRoute('<none>')),
),
array(
array('data' => $this->t('Message'), 'header' => TRUE),
......
......@@ -63,7 +63,7 @@ public static function getNextDestination(array $destinations) {
// Redirect to any given path within the same domain.
// @todo Use Url::fromPath() once https://www.drupal.org/node/2351379 is
// resolved.
$next_destination = Url::fromUri('base://' . $options['path']);
$next_destination = Url::fromUri('base:' . $options['path']);
}
return $next_destination;
}
......
......@@ -25,7 +25,7 @@ public function testTypeHandling() {
$data_with_valid_type = array(
'_links' => array(
'type' => array(
'href' => Url::fromUri('base://rest/type/entity_test/entity_test', array('absolute' => TRUE))->toString(),
'href' => Url::fromUri('base:rest/type/entity_test/entity_test', array('absolute' => TRUE))->toString(),
),
),
);
......@@ -37,10 +37,10 @@ public function testTypeHandling() {
'_links' => array(
'type' => array(
array(
'href' => Url::fromUri('base://rest/types/foo', array('absolute' => TRUE))->toString(),
'href' => Url::fromUri('base:rest/types/foo', array('absolute' => TRUE))->toString(),
),
array(
'href' => Url::fromUri('base://rest/type/entity_test/entity_test', array('absolute' => TRUE))->toString(),
'href' => Url::fromUri('base:rest/type/entity_test/entity_test', array('absolute' => TRUE))->toString(),
),
),
),
......@@ -52,7 +52,7 @@ public function testTypeHandling() {
$data_with_invalid_type = array(
'_links' => array(
'type' => array(
'href' => Url::fromUri('base://rest/types/foo', array('absolute' => TRUE))->toString(),
'href' => Url::fromUri('base:rest/types/foo', array('absolute' => TRUE))->toString(),
),
),
);
......@@ -85,7 +85,7 @@ public function testMarkFieldForDeletion() {
$no_field_data = array(
'_links' => array(
'type' => array(
'href' => Url::fromUri('base://rest/type/entity_test/entity_test', array('absolute' => TRUE))->toString(),
'href' => Url::fromUri('base:rest/type/entity_test/entity_test', array('absolute' => TRUE))->toString(),
),
),
);
......@@ -95,7 +95,7 @@ public function testMarkFieldForDeletion() {
$empty_field_data = array(
'_links' => array(
'type' => array(
'href' => Url::fromUri('base://rest/type/entity_test/entity_test', array('absolute' => TRUE))->toString(),
'href' => Url::fromUri('base:rest/type/entity_test/entity_test', array('absolute' => TRUE))->toString(),
),
),
'field_test_text' => array(),
......@@ -113,7 +113,7 @@ public function testBasicFieldDenormalization() {
$data = array(
'_links' => array(
'type' => array(
'href' => Url::fromUri('base://rest/type/entity_test/entity_test', array('absolute' => TRUE))->toString(),
'href' => Url::fromUri('base:rest/type/entity_test/entity_test', array('absolute' => TRUE))->toString(),
),
),
'uuid' => array(
......@@ -183,7 +183,7 @@ public function testPatchDenormailzation() {
$data = array(
'_links' => array(
'type' => array(
'href' => Url::fromUri('base://rest/type/entity_test/entity_test', array('absolute' => TRUE))->toString(),
'href' => Url::fromUri('base:rest/type/entity_test/entity_test', array('absolute' => TRUE))->toString(),
),
),
'field_test_text' => array(
......
......@@ -61,8 +61,8 @@ public function testNormalize() {
$entity->getTranslation('en')->set('field_test_entity_reference', array(0 => $translation_values['field_test_entity_reference']));
$entity->save();
$type_uri = Url::fromUri('base://rest/type/entity_test/entity_test', array('absolute' => TRUE))->toString();
$relation_uri = Url::fromUri('base://rest/relation/entity_test/entity_test/field_test_entity_reference', array('absolute' => TRUE))->toString();
$type_uri = Url::fromUri('base:rest/type/entity_test/entity_test', array('absolute' => TRUE))->toString();
$relation_uri = Url::fromUri('base:rest/relation/entity_test/entity_test/field_test_entity_reference', array('absolute' => TRUE))->toString();
$expected_array = array(
'_links' => array(
......
......@@ -225,7 +225,7 @@ public function buildUrl($path, $clean_urls = NULL) {
// built.
if ($clean_urls === FALSE && file_uri_scheme($uri) == 'public' && !file_exists($uri)) {
$directory_path = file_stream_wrapper_get_instance_by_uri($uri)->getDirectoryPath();
return Url::fromUri('base://' . $directory_path . '/' . file_uri_target($uri), array('absolute' => TRUE, 'query' => $token_query))->toString();
return Url::fromUri('base:' . $directory_path . '/' . file_uri_target($uri), array('absolute' => TRUE, 'query' => $token_query))->toString();
}
$file_url = file_create_url($uri);
......
......@@ -87,7 +87,7 @@ function testImageFormatterTheme() {
'#theme' => 'image_formatter',
'#image_style' => 'test',
'#item' => $entity->image_test,
'#url' => Url::fromUri('base://' . $path),
'#url' => Url::fromUri('base:' . $path),
);
// Test using theme_image_formatter() with a NULL value for the alt option.
......
......@@ -116,7 +116,7 @@ function testMenu() {
// Verify delete link exists and reset link does not exist.
$this->drupalGet('admin/structure/menu/manage/' . $this->menu->id());
$this->assertLinkByHref('admin/structure/menu/item/' . $this->items[0]->id() . '/delete');
$this->assertNoLinkByHref(Url::fromUri('base://admin/structure/menu/link/' . $this->items[0]->getPluginId() . '/reset')->toString());
$this->assertNoLinkByHref(Url::fromUri('base:admin/structure/menu/link/' . $this->items[0]->getPluginId() . '/reset')->toString());
// Check delete and reset access.
$this->drupalGet('admin/structure/menu/item/' . $this->items[0]->id() . '/delete');
$this->assertResponse(200);
......
......@@ -86,11 +86,11 @@ public function adminOverview(Request $request) {
$destination = drupal_get_destination();
foreach ($this->aliasStorage->getAliasesForAdminListing($header, $keys) as $data) {
$row = array();
$row['data']['alias'] = $this->l(Unicode::truncate($data->alias, 50, FALSE, TRUE), Url::fromUri('base://' . $data->source, array(
$row['data']['alias'] = $this->l(Unicode::truncate($data->alias, 50, FALSE, TRUE), Url::fromUri('base:' . $data->source, array(
'path_processing' => TRUE,
'attributes' => array('title' => $data->alias),
)));
$row['data']['source'] = $this->l(Unicode::truncate($data->source, 50, FALSE, TRUE), Url::fromUri('base://' . $data->source, array(
$row['data']['source'] = $this->l(Unicode::truncate($data->source, 50, FALSE, TRUE), Url::fromUri('base:' . $data->source, array(
'alias' => TRUE,
'attributes' => array('title' => $data->source),
)));
......
......@@ -54,7 +54,7 @@ public function __construct(CacheBackendInterface $cache, EntityManagerInterface
* {@inheritdoc}
*/
public function getRelationUri($entity_type, $bundle, $field_name) {
return $this->urlAssembler->assemble("base://rest/relation/$entity_type/$bundle/$field_name", array('absolute' => TRUE));
return $this->urlAssembler->assemble("base:rest/relation/$entity_type/$bundle/$field_name", array('absolute' => TRUE));
}
/**
......
......@@ -53,7 +53,7 @@ public function __construct(CacheBackendInterface $cache, UnroutedUrlAssemblerIn
*/
public function getTypeUri($entity_type, $bundle) {
// @todo Make the base path configurable.
return $this->urlAssembler->assemble("base://rest/type/$entity_type/$bundle", array('absolute' => TRUE));
return $this->urlAssembler->assemble("base:rest/type/$entity_type/$bundle", array('absolute' => TRUE));
}
/**
......
......@@ -70,7 +70,7 @@ public function testNodes() {
$data = array(
'_links' => array(
'type' => array(
'href' => Url::fromUri('base://rest/type/node/resttest', array('absolute' => TRUE))->toString(),
'href' => Url::fromUri('base:rest/type/node/resttest', array('absolute' => TRUE))->toString(),
),
),
'title' => array(
......
......@@ -63,12 +63,12 @@ function testUuidEntityResolver() {
$entity->set('field_test_entity_reference', array(array('target_id' => 1)));
$entity->save();
$field_uri = Url::fromUri('base://rest/relation/entity_test_mulrev/entity_test_mulrev/field_test_entity_reference', array('absolute' => TRUE))->toString();
$field_uri = Url::fromUri('base:rest/relation/entity_test_mulrev/entity_test_mulrev/field_test_entity_reference', array('absolute' => TRUE))->toString();
$data = array(
'_links' => array(
'type' => array(
'href' => Url::fromUri('base://rest/type/entity_test_mulrev/entity_test_mulrev', array('absolute' => TRUE))->toString(),
'href' => Url::fromUri('base:rest/type/entity_test_mulrev/entity_test_mulrev', array('absolute' => TRUE))->toString(),
),
$field_uri => array(
array(
......
......@@ -77,7 +77,7 @@ public function testInternalBrowser() {
// @see drupal_valid_test_ua()
// Not using File API; a potential error must trigger a PHP warning.
unlink($this->siteDirectory . '/.htkey');
$this->drupalGet(Url::fromUri('base://core/install.php', array('external' => TRUE, 'absolute' => TRUE))->toString());
$this->drupalGet(Url::fromUri('base:core/install.php', array('external' => TRUE, 'absolute' => TRUE))->toString());
$this->assertResponse(403, 'Cannot access install.php.');
}
......
......@@ -40,7 +40,7 @@ function statistics_help($route_name, RouteMatchInterface $route_match) {
function statistics_node_view(array &$build, EntityInterface $node, EntityViewDisplayInterface $display, $view_mode) {
if (!$node->isNew() && $view_mode == 'full' && node_is_page($node) && empty($node->in_preview)) {
$build['statistics_content_counter']['#attached']['library'][] = 'statistics/drupal.statistics';
$settings = array('data' => array('nid' => $node->id()), 'url' => Url::fromUri('base://' . drupal_get_path('module', 'statistics') . '/statistics.php')->toString());
$settings = array('data' => array('nid' => $node->id()), 'url' => Url::fromUri('base:' . drupal_get_path('module', 'statistics') . '/statistics.php')->toString());
$build['statistics_content_counter']['#attached']['drupalSettings']['statistics'] = $settings;
}
}
......
......@@ -23,15 +23,15 @@ class AddFeedTest extends WebTestBase {
function testBasicFeedAddNoTitle() {
$path = $this->randomMachineName(12);
$external_url = 'http://' . $this->randomMachineName(12) . '/' . $this->randomMachineName(12);
$fully_qualified_local_url = Url::fromUri('base://' . $this->randomMachineName(12), array('absolute' => TRUE))->toString();
$fully_qualified_local_url = Url::fromUri('base:' . $this->randomMachineName(12), array('absolute' => TRUE))->toString();
$path_for_title = $this->randomMachineName(12);
$external_for_title = 'http://' . $this->randomMachineName(12) . '/' . $this->randomMachineName(12);
$fully_qualified_for_title = Url::fromUri('base://' . $this->randomMachineName(12), array('absolute' => TRUE))->toString();
$fully_qualified_for_title = Url::fromUri('base:' . $this->randomMachineName(12), array('absolute' => TRUE))->toString();
$urls = array(
'path without title' => array(
'url' => Url::fromUri('base://' . $path, array('absolute' => TRUE))->toString(),
'url' => Url::fromUri('base:' . $path, array('absolute' => TRUE))->toString(),
'title' => '',
),
'external URL without title' => array(
......@@ -43,7 +43,7 @@ function testBasicFeedAddNoTitle() {
'title' => '',
),
'path with title' => array(
'url' => Url::fromUri('base://' . $path_for_title, array('absolute' => TRUE))->toString(),
'url' => Url::fromUri('base:' . $path_for_title, array('absolute' => TRUE))->toString(),
'title' => $this->randomMachineName(12),
),
'external URL with title' => array(
......
......@@ -32,12 +32,12 @@ function testLinkXSS() {
$text = $this->randomMachineName();
$path = "<SCRIPT>alert('XSS')</SCRIPT>";
$link = _l($text, $path);
$sanitized_path = check_url(Url::fromUri('base://' . $path)->toString());
$sanitized_path = check_url(Url::fromUri('base:' . $path)->toString());
$this->assertTrue(strpos($link, $sanitized_path) !== FALSE, format_string('XSS attack @path was filtered by _l().', array('@path' => $path)));
// Test \Drupal\Core\Url.
$link = Url::fromUri('base://' . $path)->toString();
$sanitized_path = check_url(Url::fromUri('base://' . $path)->toString());
$link = Url::fromUri('base:' . $path)->toString();
$sanitized_path = check_url(Url::fromUri('base:' . $path)->toString());
$this->assertTrue(strpos($link, $sanitized_path) !== FALSE, format_string('XSS attack @path was filtered by #theme', ['@path' => $path]));
}
......
......@@ -71,13 +71,13 @@ protected function assertBreadcrumbParts($trail) {
foreach ($trail as $path => $title) {
// If the path is empty, generate the path from the <front> route. If
// the path does not start with a leading, then run it through
// Url::fromUri('base://')->toString() to get correct the base
// Url::fromUri('base:')->toString() to get correct the base
// prepended.
if ($path == '') {
$url = Url::fromRoute('<front>')->toString();
}
elseif ($path[0] != '/') {
$url = Url::fromUri('base://' . $path)->toString();
$url = Url::fromUri('base:' . $path)->toString();
}
else {
$url = $path;
......
......@@ -37,7 +37,7 @@ protected function assertMenuActiveTrail($tree, $last_active) {
$part_xpath .= 'li[contains(@class, :class)]/a[contains(@href, :href) and contains(text(), :title)]';
$part_args = array(
':class' => 'active-trail',
':href' => Url::fromUri('base://' . $link_path)->toString(),
':href' => Url::fromUri('base:' . $link_path)->toString(),
':title' => $link_title,
);
$xpath .= $this->buildXPathQuery($part_xpath, $part_args);
......@@ -57,7 +57,7 @@ protected function assertMenuActiveTrail($tree, $last_active) {
$args = array(
':class-trail' => 'active-trail',
':class-active' => 'active',
':href' => Url::fromUri('base://' . $active_link_path)->toString(),
':href' => Url::fromUri('base:' . $active_link_path)->toString(),
':title' => $active_link_title,
);
$elements = $this->xpath($xpath, $args);
......
......@@ -278,7 +278,7 @@ function testBreadCrumbs() {
// other than the breadcrumb trail.
$elements = $this->xpath('//nav[@id=:menu]/descendant::a[@href=:href]', array(
':menu' => 'block-bartik-tools',
':href' => Url::fromUri('base://' . $link_path)->toString(),
':href' => Url::fromUri('base:' . $link_path)->toString(),
));
$this->assertTrue(count($elements) == 1, "Link to {$link_path} appears only once.");
......
......@@ -35,7 +35,7 @@ protected function assertLocalTasks(array $hrefs, $level = 0) {
));
$this->assertTrue(count($elements), 'Local tasks found.');
foreach ($hrefs as $index => $element) {
$expected = Url::fromUri('base://' . $hrefs[$index])->toString();
$expected = Url::fromUri('base:' . $hrefs[$index])->toString();
$method = ($elements[$index]['href'] == $expected ? 'pass' : 'fail');
$this->{$method}(format_string('Task @number href @value equals @expected.', array(
'@number' => $index + 1,
......
......@@ -191,7 +191,7 @@ function testLinks() {
$variables['links'] = array(
'a link' => array(
'title' => 'A <link>',
'url' => Url::fromUri('base://a/link'),
'url' => Url::fromUri('base:a/link'),
),
'plain text' => array(
'title' => 'Plain "text"',
......@@ -215,7 +215,7 @@ function testLinks() {
$expected_links = '';
$expected_links .= '<ul id="somelinks">';
$expected_links .= '<li class="a-link"><a href="' . Url::fromUri('base://a/link')->toString() . '">' . String::checkPlain('A <link>') . '</a></li>';
$expected_links .= '<li class="a-link"><a href="' . Url::fromUri('base:a/link')->toString() . '">' . String::checkPlain('A <link>') . '</a></li>';
$expected_links .= '<li class="plain-text">' . String::checkPlain('Plain "text"') . '</li>';
$expected_links .= '<li class="front-page"><a href="' . Url::fromRoute('<front>')->toString() . '">' . String::checkPlain('Front page') . '</a></li>';
$expected_links .= '<li class="router-test"><a href="' . \Drupal::urlGenerator()->generate('router_test.1') . '">' . String::checkPlain('Test route') . '</a></li>';
......@@ -254,7 +254,7 @@ function testLinks() {
);
$expected_links = '';
$expected_links .= '<ul id="somelinks">';
$expected_links .= '<li class="a-link"><a href="' . Url::fromUri('base://a/link')->toString() . '">' . String::checkPlain('A <link>') . '</a></li>';
$expected_links .= '<li class="a-link"><a href="' . Url::fromUri('base:a/link')->toString() . '">' . String::checkPlain('A <link>') . '</a></li>';
$expected_links .= '<li class="plain-text"><span class="a/class">' . String::checkPlain('Plain "text"') . '</span></li>';
$expected_links .= '<li class="front-page"><a href="' . Url::fromRoute('<front>')->toString() . '">' . String::checkPlain('Front page') . '</a></li>';
$expected_links .= '<li class="router-test"><a href="' . \Drupal::urlGenerator()->generate('router_test.1') . '">' . String::checkPlain('Test route') . '</a></li>';
......@@ -269,7 +269,7 @@ function testLinks() {
$variables['set_active_class'] = TRUE;
$expected_links = '';
$expected_links .= '<ul id="somelinks">';
$expected_links .= '<li class="a-link"><a href="' . Url::fromUri('base://a/link')->toString() . '">' . String::checkPlain('A <link>') . '</a></li>';
$expected_links .= '<li class="a-link"><a href="' . Url::fromUri('base:a/link')->toString() . '">' . String::checkPlain('A <link>') . '</a></li>';
$expected_links .= '<li class="plain-text"><span class="a/class">' . String::checkPlain('Plain "text"') . '</span></li>';
$expected_links .= '<li data-drupal-link-system-path="&lt;front&gt;" class="front-page"><a href="' . Url::fromRoute('<front>')->toString() . '" data-drupal-link-system-path="&lt;front&gt;">' . String::checkPlain('Front page') . '</a></li>';
$expected_links .= '<li data-drupal-link-system-path="router_test/test1" class="router-test"><a href="' . \Drupal::urlGenerator()->generate('router_test.1') . '" data-drupal-link-system-path="router_test/test1">' . String::checkPlain('Test route') . '</a></li>';
......
......@@ -421,7 +421,7 @@ function system_authorized_init($callback, $file, $arguments = array(), $page_ti
function system_authorized_get_url(array $options = array()) {
global $base_url;
// Prefix with $base_url so url() treats it as an external link.
$url = Url::fromUri('base://core/authorize.php');
$url = Url::fromUri('base:core/authorize.php');
$url_options = $url->getOptions();
$url->setOptions($options + $url_options);
return $url;
......
......@@ -56,7 +56,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
if (!$form_state->isValueEmpty('destination')) {
// @todo Use Url::fromPath() once https://www.drupal.org/node/2351379 is
// resolved.
$form_state->setRedirectUrl(Url::fromUri('base://' . $form_state->getValue('destination')));
$form_state->setRedirectUrl(Url::fromUri('base:' . $form_state->getValue('destination')));
}
}
else {
......
......@@ -44,7 +44,7 @@ abstract class UpdateTestBase extends WebTestBase {
protected function refreshUpdateStatus($xml_map, $url = 'update-test') {
// Tell the Update Manager module to fetch from the URL provided by
// update_test module.
$this->config('update.settings')->set('fetch.url', Url::fromUri('base://' . $url, array('absolute' => TRUE))->toString())->save();
$this->config('update.settings')->set('fetch.url', Url::fromUri('base:' . $url, array('absolute' => TRUE))->toString())->save();
// Save the map for UpdateTestController::updateTest() to use.
$this->config('update_test.settings')->set('xml_map', $xml_map)->save();
// Manually check the update status.
......
......@@ -458,7 +458,7 @@ protected function validatePath($path) {
$errors[] = $this->t('No query allowed.');
}
if (!parse_url('base://' . $path)) {
if (!parse_url('base:' . $path)) {
$errors[] = $this->t('Invalid path. Valid characters are alphanumerics as well as "-", ".", "_" and "~".');
}
......
......@@ -85,7 +85,7 @@ protected function getLinks() {
$path = strip_tags(String::decodeEntities($this->viewsTokenReplace($path, $tokens)));
$links[$field] = array(
'url' => $path ? UrlObject::fromUri('base://' . $path) : $url,
'url' => $path ? UrlObject::fromUri('base:' . $path) : $url,
'title' => $title,
);
if (!empty($this->options['destination'])) {
......
......@@ -71,7 +71,7 @@ public function testFieldUrl() {
$this->executeView($view);
$this->assertEqual(\Drupal::l('John', Url::fromUri('base://John')), $view->field['name']->advancedRender($view->result[0]));
$this->assertEqual(\Drupal::l('John', Url::fromUri('base:John')), $view->field['name']->advancedRender($view->result[0]));
}
}
......@@ -41,7 +41,7 @@ function testMenus() {
$this->drupalGet('');
$this->assertResponse(200);
$this->assertLink($view['page[link_properties][title]']);
$this->assertLinkByHref(Url::fromUri('base://' . $view['page[path]'])->toString());
$this->assertLinkByHref(Url::fromUri('base:' . $view['page[path]'])->toString());
// Make sure the link is associated with the main menu.
/** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
......
......@@ -170,7 +170,7 @@ public function testPathDestination() {
// Check that a dynamic path is shown as text.
$this->assertRaw('test_route_with_suffix/%/suffix');
$this->assertNoLinkByHref(Url::fromUri('base://test_route_with_suffix/%/suffix')->toString());
$this->assertNoLinkByHref(Url::fromUri('base:test_route_with_suffix/%/suffix')->toString());
}
/**
......
......@@ -105,10 +105,6 @@ public function testMenuOptions() {
$this->drupalPostForm('admin/structure/views/nojs/display/test_view/page_1/path', array('path' => '?bar'), t('Apply'));
$this->assertText('Path is empty');
// Add an invalid path from a random test failure.
$this->drupalPostForm('admin/structure/views/nojs/display/test_view/page_1/path', array('path' => 'AKI@&hO@'), t('Apply'));
$this->assertText('Invalid path');
// Provide a random, valid path string.
$random_string = $this->randomMachineName();
......
......@@ -318,7 +318,7 @@ public function save(array $form, FormStateInterface $form_state) {
}
// @todo Use Url::fromPath() once https://www.drupal.org/node/2351379 is
// resolved.
$form_state->setRedirectUrl(Url::fromUri("base://$destination"));
$form_state->setRedirectUrl(Url::fromUri("base:$destination"));
}
$view->save();
......@@ -424,7 +424,7 @@ public function getDisplayDetails($view, $display) {
'#options' => array('alt' => array($this->t("Go to the real page for this display"))),
// @todo Use Url::fromPath() once
// https://www.drupal.org/node/2351379 is resolved.
'#url' => Url::fromUri("base://$path"),
'#url' => Url::fromUri("base:$path"),
'#prefix' => '<li class="view">',
"#suffix" => '</li>',
);
......
......@@ -263,7 +263,7 @@ protected function getDisplayPaths(EntityInterface $view) {
if ($display->hasPath()) {
$path = $display->getPath();
if ($view->status() && strpos($path, '%') === FALSE) {
$all_paths[] = \Drupal::l('/' . $path, Url::fromUri('base://' . $path));
$all_paths[] = \Drupal::l('/' . $path, Url::fromUri('base:' . $path));
}
else {
$all_paths[] = String::checkPlain('/' . $path);
......
......@@ -702,7 +702,7 @@ public function renderPreview($display_id, $args = array()) {
Xss::filterAdmin($this->executable->getTitle()),
);
if (isset($path)) {
$path = \Drupal::l($path, Url::fromUri('base://' . $path));
$path = \Drupal::l($path, Url::fromUri('base:' . $path));
}
else {
$path = t('This display has no path.');
......
......@@ -96,7 +96,7 @@ public function testCancelLinkDestination() {
$query = array('destination' => 'baz');
$form = $this->getMock('Drupal\Core\Form\ConfirmFormInterface');
$link = ConfirmFormHelper::buildCancelLink($form, new Request($query));
$this->assertSame('base://' . $query['destination'], $link['#url']->getUri());
$this->assertSame('base:' . $query['destination'], $link['#url']->getUri());
}
}
......@@ -45,7 +45,7 @@ class UnroutedUrlTest extends UnitTestCase {
*
* @var string
*/
protected $unroutedInternal = 'base://robots.txt';
protected $unroutedInternal = 'base:robots.txt';
/**
* {@inheritdoc}
......@@ -69,20 +69,53 @@ protected function setUp() {
* Tests the fromUri() method.
*
* @covers ::fromUri
*
* @dataProvider providerFromUri
*/
public function testFromUri() {
$urls = [
Url::fromUri($this->unroutedExternal),
Url::fromUri($this->unroutedInternal)
];
public function testFromUri($uri, $is_external) {
$url = Url::fromUri($uri);
$this->assertInstanceOf('Drupal\Core\Url', $url);
}
$this->assertInstanceOf('Drupal\Core\Url', $urls[0