From a71337b86fbbbf7a0226a34e490f80756869f49b Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Wed, 29 May 2019 10:41:42 +0100 Subject: [PATCH] Issue #3045211 by nlisgo, yogeshmpawar, Nebel54, heddn, quietone: Prevent link field migration from creating invalid link attributes --- .../src/Plugin/migrate/process/FieldLink.php | 4 +++- .../Plugin/migrate/process/FieldLinkTest.php | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/core/modules/link/src/Plugin/migrate/process/FieldLink.php b/core/modules/link/src/Plugin/migrate/process/FieldLink.php index 680049ce5088..9af61f176e7c 100644 --- a/core/modules/link/src/Plugin/migrate/process/FieldLink.php +++ b/core/modules/link/src/Plugin/migrate/process/FieldLink.php @@ -119,7 +119,9 @@ class FieldLink extends ProcessPluginBase { $attributes = unserialize($attributes); } - if (!$attributes) { + // In rare cases Drupal 6/7 link attributes are triple serialized. To avoid + // further problems with them we set them to an empty array in this case. + if (!is_array($attributes)) { $attributes = []; } 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 f765f6af357d..905d49e86b2a 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 @@ -89,4 +89,27 @@ class FieldLinkTest extends UnitTestCase { ]; } + /** + * Test the attributes that are deeply serialized are discarded. + */ + public function testCanonicalizeUriSerialized() { + $link_plugin = new FieldLink([], '', [], $this->getMock(MigrationInterface::class)); + $migrate_executable = $this->getMock(MigrateExecutableInterface::class); + $row = new Row(); + + $transformed = $link_plugin->transform([ + 'url' => '', + 'title' => '', + 'attributes' => serialize(serialize(['not too deep'])), + ], $migrate_executable, $row, NULL); + $this->assertEquals(['not too deep'], $transformed['options']['attributes']); + + $transformed = $link_plugin->transform([ + 'url' => '', + 'title' => '', + 'attributes' => serialize(serialize(serialize(['too deep']))), + ], $migrate_executable, $row, NULL); + $this->assertEmpty($transformed['options']['attributes']); + } + }