function UrlHelper::isExternal

Same name in other branches
  1. 9 core/lib/Drupal/Component/Utility/UrlHelper.php \Drupal\Component\Utility\UrlHelper::isExternal()
  2. 10 core/lib/Drupal/Component/Utility/UrlHelper.php \Drupal\Component\Utility\UrlHelper::isExternal()
  3. 11.x core/lib/Drupal/Component/Utility/UrlHelper.php \Drupal\Component\Utility\UrlHelper::isExternal()

Determines whether a path is external to Drupal.

An example of an external path is 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.

21 calls to UrlHelper::isExternal()
CredentialForm::validatePaths in core/modules/migrate_drupal_ui/src/Form/CredentialForm.php
The #element_validate handler for the source path elements.
DisplayPluginBase::getMoreUrl in core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
Get the more URL for this view.
Endpoint::__construct in core/modules/media/src/OEmbed/Endpoint.php
Endpoint constructor.
FieldPluginBase::renderText in core/modules/views/src/Plugin/views/field/FieldPluginBase.php
Performs an advanced text render for the item.
FormBuilder::doBuildForm in core/lib/Drupal/Core/Form/FormBuilder.php
Builds and processes all elements in the structured form array.

... See full list

File

core/lib/Drupal/Component/Utility/UrlHelper.php, line 213

Class

UrlHelper
Helper class URL based methods.

Namespace

Drupal\Component\Utility

Code

public static function isExternal($path) {
    $colonpos = strpos($path, ':');
    // Some browsers treat \ as / so normalize to forward slashes.
    $path = str_replace('\\', '/', $path);
    // If the path starts with 2 slashes then it is always considered an
    // external URL without an explicit protocol part.
    return strpos($path, '//') === 0 || preg_match('/^\\p{C}/u', $path) !== 0 || $colonpos !== FALSE && !preg_match('![/?#]!', substr($path, 0, $colonpos)) && static::stripDangerousProtocols($path) == $path;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.