From 132a42bf3614192ced2bb78c61507c008d1f5860 Mon Sep 17 00:00:00 2001
From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org>
Date: Wed, 14 Feb 2018 14:35:06 +0000
Subject: [PATCH] Issue #2942388 by alexpott, quietone: Ensure d7_url_alias
 migration works for paths without a slashes

---
 core/modules/migrate_drupal/tests/fixtures/drupal7.php   | 6 ++++++
 core/modules/path/migrations/d7_url_alias.yml            | 2 ++
 .../tests/src/Kernel/Migrate/d7/MigrateUrlAliasTest.php  | 9 ++++++++-
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal7.php b/core/modules/migrate_drupal/tests/fixtures/drupal7.php
index a7117303e72a..27eb713ae11d 100644
--- a/core/modules/migrate_drupal/tests/fixtures/drupal7.php
+++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php
@@ -45982,6 +45982,12 @@
   'alias' => 'firefly',
   'language' => 'en',
 ))
+->values(array(
+  'pid' => '6',
+  'source' => 'admin',
+  'alias' => 'source-noslash',
+  'language' => 'und',
+))
 ->execute();
 
 $connection->schema()->createTable('users', array(
diff --git a/core/modules/path/migrations/d7_url_alias.yml b/core/modules/path/migrations/d7_url_alias.yml
index dffaf46825d1..6b148eba53bd 100644
--- a/core/modules/path/migrations/d7_url_alias.yml
+++ b/core/modules/path/migrations/d7_url_alias.yml
@@ -24,7 +24,9 @@ process:
       source: source
       delimiter: /
     -
+      # If the source path has no slashes return a dummy default value.
       plugin: extract
+      default: 'INVALID_NID'
       index:
         - 1
     -
diff --git a/core/modules/path/tests/src/Kernel/Migrate/d7/MigrateUrlAliasTest.php b/core/modules/path/tests/src/Kernel/Migrate/d7/MigrateUrlAliasTest.php
index 2edf258eea80..dae024950010 100644
--- a/core/modules/path/tests/src/Kernel/Migrate/d7/MigrateUrlAliasTest.php
+++ b/core/modules/path/tests/src/Kernel/Migrate/d7/MigrateUrlAliasTest.php
@@ -48,7 +48,9 @@ protected function setUp() {
    * Test the URL alias migration.
    */
   public function testUrlAlias() {
-    $path = \Drupal::service('path.alias_storage')->load([
+    $alias_storage = $this->container->get('path.alias_storage');
+
+    $path = $alias_storage->load([
       'source' => '/taxonomy/term/4',
       'alias' => '/term33',
       'langcode' => 'und',
@@ -56,6 +58,11 @@ public function testUrlAlias() {
     $this->assertIdentical('/taxonomy/term/4', $path['source']);
     $this->assertIdentical('/term33', $path['alias']);
     $this->assertIdentical('und', $path['langcode']);
+
+    // Alias with no slash.
+    $path = $alias_storage->load(['alias' => '/source-noslash']);
+    $this->assertSame('/admin', $path['source']);
+    $this->assertSame('und', $path['langcode']);
   }
 
   /**
-- 
GitLab