Commit c8e8d6d2 authored by Sascha Grossenbacher's avatar Sascha Grossenbacher Committed by Sascha Grossenbacher
Browse files

Issue #3059894 by nileema19, Berdir: Redirect loop can occur in sub-requests

parent cb653986
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -99,6 +99,8 @@ class RedirectRepository {
      return $redirect;
    }

    // Reset found redirects.
    $this->foundRedirects = [];
    return NULL;
  }

+26 −0
Original line number Diff line number Diff line
@@ -239,6 +239,32 @@ class RedirectAPITest extends KernelTestBase {
    }
  }

  /**
   * Test loop detection reset.
   */
  public function testLoopDetectionReset() {
    // Add a chained redirect that isn't a loop.
    /** @var \Drupal\redirect\Entity\Redirect $source */
    $source = $this->controller->create();
    $source->setSource('source-redirect');
    $source->setRedirect('target');
    $source->save();

    /** @var \Drupal\redirect\Entity\Redirect $target */
    $target = $this->controller->create();
    $target->setSource('target');
    $target->setRedirect('second-target');
    $target->save();

    /** @var \Drupal\redirect\RedirectRepository $repository */
    $repository = \Drupal::service('redirect.repository');
    $found = $repository->findMatchingRedirect('target');
    $this->assertEquals($target->id(), $found->id());

    $found = $repository->findMatchingRedirect('source-redirect');
    $this->assertEquals($target->id(), $found->id());
  }

  /**
   * Test redirect_parse_url().
   */