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

Skip to content

Symfony\Component\HttpFoundation\Request::prepareBaseUrl() is empty #34866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mvorisek opened this issue Dec 6, 2019 · 1 comment
Closed

Comments

@mvorisek
Copy link
Contributor

mvorisek commented Dec 6, 2019

Description
When webserver (file) root is more specific than the request (URL) root, the current Symfony\Component\HttpFoundation\Request::prepareBaseUrl() method

protected function prepareBaseUrl()
does not work.

This is core method and it needs to be fixed asap.

How to reproduce

$request = Request::createFromGlobals();

(\Closure::bind(function() use($request) {
    var_dump($_SERVER['SCRIPT_FILENAME']);
    var_dump($_SERVER['SCRIPT_NAME']);
    var_dump($_SERVER['PHP_SELF']);
    var_dump($this->getRequestUri()); // used in Symfony\Component\HttpFoundation\Request::prepareBaseUrl()
    var_dump($request->getBaseUrl()); // calls Symfony\Component\HttpFoundation\Request::prepareBaseUrl() on the first time
}, $request, \Symfony\Component\HttpFoundation\Request::class))();

Webserver config: serve requests with path ^/ps/*$ from C:/data/psmigr/ps_dev/ root directory

Current results

  • access from http://localhost/ps/pslrel18/adminX/
    string(65) "C:/data/psmigr/ps_dev/pslrel18/adminX/index.php"
    string(26) "/pslrel18/adminX/index.php"
    string(26) "/pslrel18/adminX/index.php"
    string(20) "/ps/pslrel18/adminX/"
    string(20) "/ps/pslrel18/adminX/"
    string(0) ""
    
  • access from http://localhost/ps/pslrel18/adminX/something
    string(65) "C:/data/psmigr/ps_dev/pslrel18/adminX/index.php"
    string(26) "/pslrel18/adminX/index.php"
    string(26) "/pslrel18/adminX/index.php"
    string(29) "/ps/pslrel18/adminX/something"
    string(29) "/ps/pslrel18/adminX/something"
    string(0) ""
    
  • access from http://localhost/ps/pslrel18/adminX/index.php
    string(65) "C:/data/psmigr/ps_dev/pslrel18/adminX/index.php"
    string(26) "/pslrel18/adminX/index.php"
    string(26) "/pslrel18/adminX/index.php"
    string(29) "/ps/pslrel18/adminX/index.php"
    string(29) "/ps/pslrel18/adminX/index.php"
    string(29) "/ps/pslrel18/adminX/index.php"
    

Notice the last var_dump in each result.

Expected results

  • access from http://localhost/ps/pslrel18/adminX/
    string(65) "C:/data/psmigr/ps_dev/pslrel18/adminX/index.php"
    string(26) "/pslrel18/adminX/index.php"
    string(26) "/pslrel18/adminX/index.php"
    string(20) "/ps/pslrel18/adminX/"
    string(20) "/ps/pslrel18/adminX/"
    string(29) "/ps/pslrel18/adminX/index.php"
    
  • access from http://localhost/ps/pslrel18/adminX/something
    string(65) "C:/data/psmigr/ps_dev/pslrel18/adminX/index.php"
    string(26) "/pslrel18/adminX/index.php"
    string(26) "/pslrel18/adminX/index.php"
    string(29) "/ps/pslrel18/adminX/something"
    string(29) "/ps/pslrel18/adminX/something"
    string(29) "/ps/pslrel18/adminX/index.php"
    
  • access from http://localhost/ps/pslrel18/adminX/index.php
    string(65) "C:/data/psmigr/ps_dev/pslrel18/adminX/index.php"
    string(26) "/pslrel18/adminX/index.php"
    string(26) "/pslrel18/adminX/index.php"
    string(29) "/ps/pslrel18/adminX/index.php"
    string(29) "/ps/pslrel18/adminX/index.php"
    string(29) "/ps/pslrel18/adminX/index.php"
    
@mvorisek
Copy link
Contributor Author

@fabpot Please reopen, this is a major issue and it affects all users whose have some URL part (like /~username/, i.e. not root like /) mapped to some directory which is then considered as a root dir.

mvorisek added a commit to mvorisek/symfony that referenced this issue Oct 17, 2020
mvorisek added a commit to mvorisek/symfony that referenced this issue Oct 17, 2020
mvorisek added a commit to mvorisek/symfony that referenced this issue Oct 17, 2020
mvorisek added a commit to mvorisek/symfony that referenced this issue Oct 17, 2020
mvorisek added a commit to mvorisek/symfony that referenced this issue Oct 17, 2020
mvorisek added a commit to mvorisek/symfony that referenced this issue Oct 17, 2020
derrabus added a commit that referenced this issue Nov 15, 2020
…vorisek)

This PR was merged into the 4.4 branch.

Discussion
----------

[HttpFoundation] Fix for virtualhosts based on URL path

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #34866
| License       | MIT
| Doc PR        | no

This PR fixes base URL detection when:
- virtualhost is based on URL path
- AND local path does not match that URL virtual host path prefix

fix covered with tests

Commits
-------

75ff868 [HttpFoundation] Fix for virtualhosts based on URL path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants