Issue #3232681 by Matroskeen, danflanagan8, kpaxman, quietone: FieldLink process plugin treats protocol-relative external URLs as internal ones

merge-requests/1067/merge
Alex Pott 2021-10-18 10:36:12 +01:00
parent 4bc7dbb8f9
commit e57ef27b2d
No known key found for this signature in database
GPG Key ID: BDA67E7EE836E5CE
2 changed files with 11 additions and 0 deletions

View File

@ -59,6 +59,13 @@ class FieldLink extends ProcessPluginBase {
* @see \Drupal\link\Plugin\Field\FieldWidget\LinkWidget::getUserEnteredStringAsUri()
*/
protected function canonicalizeUri($uri) {
// If the path starts with 2 slashes then it is always considered an
// external URL without an explicit protocol part.
// @todo Remove this when https://www.drupal.org/node/2744729 lands.
if (strpos($uri, '//') === 0) {
return $this->configuration['uri_scheme'] . ltrim($uri, '/');
}
// If we already have a scheme, we're fine.
if (parse_url($uri, PHP_URL_SCHEME)) {
return $uri;

View File

@ -66,6 +66,10 @@ class FieldLinkTest extends UnitTestCase {
'https://yahoo.com',
['uri_scheme' => 'https://'],
],
'Absolute URL without explicit protocol (protocol-relative)' => [
'//example.com',
'http://example.com',
],
'Absolute URL with non-standard characters' => [
'http://www.ßÀÑÐ¥ƒå¢ë.com',
'http://www.ßÀÑÐ¥ƒå¢ë.com',