Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpFoundation] Problem with Request::getBaseUrl and url-rewrites #7329

Closed
@nicmart

Description

@nicmart

I've encountered an inconsistent behavior with Request::getBaseUrl method when the Request URI does not include the SCRIPT_NAME (due for example to an apache url rewrite), but it includes a segment of the SCRIPT_NAME path.

In RequestTest.php, if I add this data to the getBaseUrlData data provider, testGetBaseUrl fails:

//Test Fails
array(
    '/webmaster',
    array(
        'SCRIPT_FILENAME' => '/foo/bar/web/index.php',
        'SCRIPT_NAME'     => '/web/index.php',
        'PHP_SELF'        => '/web/index.php',
    ),
    '',            //getBaseUrl    Fails, '/web' returned
    '/webmaster',  //getPathInfo   Fails, 'master' returned
)

because in this case getBaseUrl returns '/web' and not ''. This make getPathInfo fails too (it returns 'master' instead of '/webmaster'),

If the URI does not start with 'web' all works as expected:

//Test passes
array(
    '/administrator',
    array(
        'SCRIPT_FILENAME' => '/foo/bar/web/index.php',
        'SCRIPT_NAME'     => '/web/index.php',
        'PHP_SELF'        => '/web/index.php',
    ),
    '',          //getBaseUrl
    '/administrator', //getPathInfo
)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions