Commit ee387f37 authored by catch's avatar catch
Browse files

Issue #268909 by maartenvg, raman.b, paulocs, lyricnz, Abhijith S, webchick,...

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

(cherry picked from commit 29689c24)
parent 608d53a1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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 */
+6 −0
Original line number Diff line number Diff line
@@ -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.