diff --git a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php index 3f8944f..6657c47 100644 --- a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php +++ b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php @@ -1371,21 +1371,35 @@ protected function renderAsLink($alter, $text, $tokens) { // strip_tags() and viewsTokenReplace remove , so check whether it's // different to front. if ($path != '') { - // Use strip tags as there should never be HTML in the path. - // However, we need to preserve special characters like " that - // were removed by SafeMarkup::checkPlain(). + // Use strip_tags as there should never be HTML in the path. + // However, we need to preserve special characters like " that were + // removed by SafeMarkup::checkPlain(). $path = Html::decodeEntities($this->viewsTokenReplace($alter['path'], $tokens)); - strip_tags($path); + + // Tokens might contain , so check for again. + if ($path != '') { + $path = strip_tags($path); + } + + // Tokens might have resolved URL's, as is the case for tokens provided by + // Link fields, so all internal paths will be prefixed by base_path(). For + // proper further handling reset this to internal:/. + if (strpos($path, base_path()) === 0) { + $path = str_replace(base_path(), 'internal:/', $path); + } // If we have no $path and no $alter['url'], we have nothing to work with, // so we just return the text. - if (empty($path) && empty($alter['url'])) return $text; + if (empty($path) && empty($alter['url'])) { + return $text; + } // If no scheme is provided in the $path, assign the default 'http://'. // This allows a url of 'www.example.com' to be converted to // 'http://www.example.com'. - // Only do this on for external URLs. - if ($alter['external'] && !parse_url($path, PHP_URL_SCHEME)) { + // Only do this when flag for external has been set, $path doesn't contain + // a scheme and $path doesn't have a leading /. + if ($alter['external'] && !parse_url($path, PHP_URL_SCHEME) && strpos($path, '/') !== 0) { // There is no scheme, add the default 'http://' to the $path. $path = "http://" . $path; }