You are here

public function RouterTest::testSuccessiveSlashes in Drupal 10

Ensure that multiple successive slashes are redirected.

File

core/modules/system/tests/src/Functional/Routing/RouterTest.php, line 327

Class

RouterTest
Functional class for the full integrated routing system.

Namespace

Drupal\Tests\system\Functional\Routing

Code

public function testSuccessiveSlashes() {
  $request = $this->container
    ->get('request_stack')
    ->getCurrentRequest();

  // Test a simple path with successive leading slashes.
  $url = $request
    ->getUriForPath('//////router_test/test1');
  $this
    ->drupalGet($url);
  $this
    ->assertSession()
    ->addressEquals($request
    ->getUriForPath('/router_test/test1'));

  // Test successive slashes in the middle.
  $url = $request
    ->getUriForPath('/router_test//////test1') . '?qs=test';
  $this
    ->drupalGet($url);
  $this
    ->assertSession()
    ->addressEquals($request
    ->getUriForPath('/router_test/test1') . '?qs=test');

  // Ensure that external URLs in destination query params are not redirected
  // to.
  $url = $request
    ->getUriForPath('/////////////////////////////////////////////////router_test/test1') . '?qs=test&destination=http://www.example.com%5c@drupal8alt.test';
  $this
    ->drupalGet($url);
  $this
    ->assertSession()
    ->addressEquals($request
    ->getUriForPath('/router_test/test1') . '?qs=test');
}