Commit 5118c6dc authored by Dani Wisnousky's avatar Dani Wisnousky Committed by Dave Reid
Browse files

Issue #2932615 by Majdi, bkosborne, prempatel2447, jhedstrom, nachosalvador,...

Issue #2932615 by Majdi, bkosborne, prempatel2447, jhedstrom, nachosalvador, dwisnousky: Remove trailing slashes from redirect source paths to allow matching.
parent c90cb932
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -85,6 +85,11 @@ class Redirect extends ContentEntityBase {
   * {@inheritdoc}
   */
  public function preSave(EntityStorageInterface $storage_controller) {
    // Strip any trailing slashes as these are removed when looking for matching
    // redirects.
    // @see \Drupal\redirect\EventSubscriber\RedirectRequestSubscriber::onKernelRequestCheckRedirect()
    $this->redirect_source->path = rtrim($this->redirect_source->path, '/');

    // Get the language code directly from the field as language() might not
    // be up to date if the language was just changed.
    $this->set('hash', Redirect::generateHash($this->redirect_source->path, (array) $this->redirect_source->query, $this->get('language')->value));
+2 −1
Original line number Diff line number Diff line
@@ -167,7 +167,8 @@ class RedirectAPITest extends KernelTestBase {
   */
  public function testDuplicateRedirectEntry() {
    $redirect = $this->storage->create();
    $redirect->setSource('/foo/foo', []);
    // The trailing slash should be removed on pre-save.
    $redirect->setSource('/foo/foo/', []);
    $redirect->setRedirect('foo');
    $redirect->save();