function RouterTest::testLeadingSlashes

Ensure that multiple leading slashes are redirected.

File

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

Class

RouterTest
Functional class for the full integrated routing system.

Namespace

Drupal\Tests\system\Functional\Routing

Code

public function testLeadingSlashes() {
    $request = $this->container
        ->get('request_stack')
        ->getCurrentRequest();
    $url = $request->getUriForPath('//router_test/test1');
    $this->drupalGet($url);
    $this->assertUrl($request->getUriForPath('/router_test/test1'));
    // It should not matter how many leading slashes are used and query strings
    // should be preserved.
    $url = $request->getUriForPath('/////////////////////////////////////////////////router_test/test1') . '?qs=test';
    $this->drupalGet($url);
    $this->assertUrl($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->assertUrl($request->getUriForPath('/router_test/test1') . '?qs=test');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.