From e57ef27b2dd45f5a84abad534d8132f9d6317c10 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Mon, 18 Oct 2021 10:36:12 +0100 Subject: [PATCH] Issue #3232681 by Matroskeen, danflanagan8, kpaxman, quietone: FieldLink process plugin treats protocol-relative external URLs as internal ones --- core/modules/link/src/Plugin/migrate/process/FieldLink.php | 7 +++++++ .../src/Unit/Plugin/migrate/process/FieldLinkTest.php | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/core/modules/link/src/Plugin/migrate/process/FieldLink.php b/core/modules/link/src/Plugin/migrate/process/FieldLink.php index 8dcf41fb90e3..c3efed474d41 100644 --- a/core/modules/link/src/Plugin/migrate/process/FieldLink.php +++ b/core/modules/link/src/Plugin/migrate/process/FieldLink.php @@ -59,6 +59,13 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition * @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; diff --git a/core/modules/link/tests/src/Unit/Plugin/migrate/process/FieldLinkTest.php b/core/modules/link/tests/src/Unit/Plugin/migrate/process/FieldLinkTest.php index d6721e51f2e5..1142ec0c2005 100644 --- a/core/modules/link/tests/src/Unit/Plugin/migrate/process/FieldLinkTest.php +++ b/core/modules/link/tests/src/Unit/Plugin/migrate/process/FieldLinkTest.php @@ -66,6 +66,10 @@ public function canonicalizeUriDataProvider() { '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', -- GitLab