From 29689c24f39495fc119a80b2d8b8bbe4acc63789 Mon Sep 17 00:00:00 2001 From: catch Date: Mon, 16 Nov 2020 12:47:43 +0000 Subject: [PATCH] Issue #268909 by maartenvg, raman.b, paulocs, lyricnz, Abhijith S, webchick, Freso, chx, pameeela: "0" can't be used a path alias, but no error is shown --- .../path/src/Plugin/Field/FieldWidget/PathWidget.php | 2 +- core/modules/path/tests/src/Functional/PathAliasTest.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php b/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php index c222171e10..441c65c94f 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 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen 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 5ebaadae89..19fd491253 100644 --- a/core/modules/path/tests/src/Functional/PathAliasTest.php +++ b/core/modules/path/tests/src/Functional/PathAliasTest.php @@ -345,6 +345,12 @@ public function testNodeAlias() { // 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. -- GitLab