You are here

public static function UrlHelper::isExternal in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Component/Utility/UrlHelper.php \Drupal\Component\Utility\UrlHelper::isExternal()

Determines whether a path is external to Drupal (e.g. http://example.com).

If a path cannot be assessed by Drupal's menu handler, then we must treat it as potentially insecure.

Parameters

string $path: The internal path or external URL being linked to, such as "node/34" or "http://example.com/foo".

Return value

bool TRUE or FALSE, where TRUE indicates an external path.

14 calls to UrlHelper::isExternal()
BrowserTestBase::drupalGet in core/modules/simpletest/src/BrowserTestBase.php
Retrieves a Drupal path or an absolute path.
FormBuilder::doBuildForm in core/lib/Drupal/Core/Form/FormBuilder.php
Builds and processes all elements in the structured form array.
GotoAction::execute in core/modules/action/src/Plugin/Action/GotoAction.php
Executes the plugin.
LocalAwareRedirectResponseTrait::isLocal in core/lib/Drupal/Core/Routing/LocalAwareRedirectResponseTrait.php
PathValidator::getUrl in core/lib/Drupal/Core/Path/PathValidator.php
Helper for getUrlIfValid() and getUrlIfValidWithoutAccessCheck().

... See full list

File

core/lib/Drupal/Component/Utility/UrlHelper.php, line 215
Contains \Drupal\Component\Utility\UrlHelper.

Class

UrlHelper
Helper class URL based methods.

Namespace

Drupal\Component\Utility

Code

public static function isExternal($path) {
  $colonpos = strpos($path, ':');

  // Avoid calling drupal_strip_dangerous_protocols() if there is any slash
  // (/), hash (#) or question_mark (?) before the colon (:) occurrence - if
  // any - as this would clearly mean it is not a URL. If the path starts with
  // 2 slashes then it is always considered an external URL without an
  // explicit protocol part.
  return strpos($path, '//') === 0 || $colonpos !== FALSE && !preg_match('![/?#]!', substr($path, 0, $colonpos)) && static::stripDangerousProtocols($path) == $path;
}