Skip to content
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

Fix base URL bug #8508

Closed
wants to merge 1 commit into from
Closed

Fix base URL bug #8508

wants to merge 1 commit into from

Conversation

lukasgeiter
Copy link
Contributor

This solves the issue #8441

It might not be considered as a real bug, but the Symfony Request makes a mistake when determining the base URL of a request.
If the application is running under domain root, following URLs will all produce the same path info:

http://laravel.app/
http://laravel.app/foo/bar/index.php

foo/bar can be replaced with anything, the page will still work and not return a 404.

For a live example hit: http://laravel.com/foo/index.php/docs/5.0/

This PR fixes that behavior but I'd really like some feedback from you guys:

  1. Is it OK to fix this just within Laravel or should it be fixed in the Symfony Request class?
  2. I'm unsure if this covers all (necessary) cases. Especially since the original prepareBaseUrl() is a lot more complicated. What do you think?

@GrahamCampbell
Copy link
Member

Please fix all the cs issues.

@GrahamCampbell
Copy link
Member

Does this break things for people running laravel in a folder?

@lukasgeiter
Copy link
Contributor Author

Sorry about the code style. Should be good now...

It does not break things for running it in a sub directory. (At least it didn't for me)

protected function prepareBaseUrl()
{
$scriptName = $this->server->get('SCRIPT_NAME');
if(starts_with(ltrim($this->server->get('REQUEST_URI'), '/'), ltrim($scriptName, '/')))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing space

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where exactly? Are there any more specific style guidelines regarding spacing? (other than PSR-1 and that bit in the docs)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before the opening bracket just after the if.

@lukasgeiter
Copy link
Contributor Author

I've fixed all the coding style issues (I hope) and also fixed a little bug for generating URLs when running under root on windows (strangely dirname() will return a backslash which needs to be trimmed)

@montogeek
Copy link

Thanks!

@GrahamCampbell
Copy link
Member

Please squash to one commit.

@GrahamCampbell
Copy link
Member

I actually can't replicate this bug anyway. StyleCI runs laravel 5.0, and https://styleci.io/123/donate shows 404 correctly. It looks like it's caused by server missconfiguration, rather than a bug with laravel.

@lukasgeiter
Copy link
Contributor Author

You have to actually put index.php in the URL. Like https://styleci.io/123/index.php/donate

@GrahamCampbell
Copy link
Member

Oh right. My bad.

@taylorotwell
Copy link
Member

Then send a PR to Symfony.

@lukasgeiter
Copy link
Contributor Author

Hmm. In an effort to do that I just discovered that the symfony site itself handles this case correctly.
http://symfony.com/foo/app.php/jobs shows a 404 page like it should.

@GrahamCampbell
Copy link
Member

symfony.com is running drupal though, so it's not totally using the same routing system.

@lukasgeiter
Copy link
Contributor Author

Ahh well that's an explanation ;)
Do you know any symfony sites?

@PatrickBauer
Copy link

symfony.com is not running on drupal. At least there is no indicator for this. Why wouldn't it run on symfony?

@cryptiklemur
Copy link

HEAVILY NSFW

Only site i can think of http://www.youporn.com/app/app.php

But it does do work as this bug suggests.

@lukasgeiter
Copy link
Contributor Author

@aequasi Haha I definitely won't use that example in a bug report / PR...

@javiereguiluz
Copy link

Sorry to interrupt your discussion, but regarding this comment:

symfony.com is running drupal though, so it's not totally using the same routing system.

I'm afraid that's not true. I'm the guy in charge of symfony.com development, so I can assure you that the site is developed using the latest stable version of the Symfony full-stack framework.

@lukasgeiter
Copy link
Contributor Author

@javiereguiluz You're not interrupting at all. Thanks for clearing that up.

I guess my next step will be setting up a symfony application myself to do some testing...

@cryptiklemur
Copy link

set up a quick app on Heroku for the PR, using the demo app. Should be pretty easy

@lukasgeiter
Copy link
Contributor Author

@aequasi Sure, just thought it would be nice to demonstrate the bug on a big site...

@lancepioch
Copy link
Contributor

@lukasgeiter Here's a fun example.

@garygreen
Copy link
Contributor

@garygreen
Copy link
Contributor

I did a issue for this on Symphony, seems there is a PR to fix the issue hopefully will get merged. Haven't tested if it fixes the issue yet symfony/symfony#13617 pr: symfony/symfony#14335

@lukasgeiter
Copy link
Contributor Author

@garygreen I've just tried the PR and it didn't change anything...

I also found a live example: http://cmf.symfony.com/foo/bar/app.php/news

@lukasgeiter
Copy link
Contributor Author

Created a PR: symfony/symfony#14468

Let's see how that goes...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants