diff --git a/core/modules/path/src/Form/PathFormBase.php b/core/modules/path/src/Form/PathFormBase.php index 3d8b283..b5505d0 100644 --- a/core/modules/path/src/Form/PathFormBase.php +++ b/core/modules/path/src/Form/PathFormBase.php @@ -152,7 +152,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) { $source = $this->aliasManager->getPathByAlias($source); $alias = $form_state->getValue('alias'); // Trim the submitted value of whitespace and slashes. - $alias = trim(trim($alias), '/'); + $alias = trim($alias, " \t\n\r\0\x0B\\/"); // Language is only set if language.module is enabled, otherwise save for all // languages. $langcode = $form_state->getValue('langcode', LanguageInterface::LANGCODE_NOT_SPECIFIED); @@ -177,7 +177,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $source = $this->aliasManager->getPathByAlias($source); $alias = $form_state->getValue('alias'); // Trim the submitted value of whitespace and slashes. - $alias = trim(trim($alias), '/'); + $alias = trim($alias, " \t\n\r\0\x0B\\/"); // Language is only set if language.module is enabled, otherwise save for all // languages. $langcode = $form_state->getValue('langcode', LanguageInterface::LANGCODE_NOT_SPECIFIED); diff --git a/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php b/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php index 1a62b28..8316989 100644 --- a/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php +++ b/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php @@ -85,7 +85,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 = trim(trim($element['alias']['#value']), '/'); + $alias = trim($element['alias']['#value'], " \t\n\r\0\x0B\\/"); if (!empty($alias)) { $form_state->setValueForElement($element['alias'], $alias); diff --git a/core/modules/path/src/Tests/PathAliasTest.php b/core/modules/path/src/Tests/PathAliasTest.php index c61c6b6..f1dc2a5 100644 --- a/core/modules/path/src/Tests/PathAliasTest.php +++ b/core/modules/path/src/Tests/PathAliasTest.php @@ -150,7 +150,7 @@ function testAdminAlias() { // Create alias with trailing slash. $edit = array(); - $edit['source'] = 'node/' . $node3->id(); + $edit['source'] = 'node/' . $node4->id(); $edit['alias'] = $this->randomMachineName(8) . '/'; $this->drupalPostForm('admin/config/search/path/add', $edit, t('Save'));