diff --git a/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php b/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php index c222171e103..441c65c94fc 100644 --- a/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php +++ b/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php @@ -84,7 +84,7 @@ class PathWidget extends WidgetBase { public static function validateFormElement(array &$element, FormStateInterface $form_state) { // Trim the submitted value of whitespace and slashes. $alias = rtrim(trim($element['alias']['#value']), " \\/"); - if (!empty($alias)) { + if ($alias !== '') { $form_state->setValueForElement($element['alias'], $alias); /** @var \Drupal\path_alias\PathAliasInterface $path_alias */ diff --git a/core/modules/path/tests/src/Functional/PathAliasTest.php b/core/modules/path/tests/src/Functional/PathAliasTest.php index 5ebaadae894..19fd491253b 100644 --- a/core/modules/path/tests/src/Functional/PathAliasTest.php +++ b/core/modules/path/tests/src/Functional/PathAliasTest.php @@ -345,6 +345,12 @@ class PathAliasTest extends PathTestBase { // Create sixth test node. $node6 = $this->drupalCreateNode(); + // Test the special case where the alias is '0'. + $edit = ['path[0][alias]' => '0']; + $this->drupalGet($node6->toUrl('edit-form')); + $this->submitForm($edit, 'Save'); + $this->assertSession()->pageTextContains('The alias path has to start with a slash.'); + // Create an invalid alias with two leading slashes and verify that the // extra slash is removed when the link is generated. This ensures that URL // aliases cannot be used to inject external URLs.