public static UrlHelper::isExternal($path)
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.
File
- core/lib/Drupal/Component/Utility/UrlHelper.php, line 211
Class
- UrlHelper
- Helper class URL based methods.
Namespace
Drupal\Component\Utility
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 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) // Leading control characters may be ignored or mishandled by browsers, // so assume such a path may lead to an external location. The \p{C} // character class matches all UTF-8 control, unassigned, and private // characters. || (preg_match( '/^\p{C}/u' , $path ) !== 0) // Avoid calling static::stripDangerousProtocols() 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. || ( $colonpos !== FALSE && !preg_match( '![/?#]!' , substr ( $path , 0, $colonpos )) && static ::stripDangerousProtocols( $path ) == $path ); } |
Please login to continue.