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 the edge case of double leading slash when rebuilding request #167

Merged
merged 1 commit into from
Jan 21, 2016

Conversation

dbu
Copy link
Member

@dbu dbu commented Jan 10, 2016

fix #166

@sustmi you are right. as it turns out, even specifying the host explicitly, Request::create('//test') considers the path as a domain. i now rebuild the full URL, i do hope this now works.

note that you will need to do setContext with the RequestContext for this to work. if there is no request context, we don't do anything more than before the fix.

if (isset($server['HTTP_HOST'])) {
$pathinfo = $server['HTTP_HOST'].$pathinfo;
} else {
$pathinfo = 'localhost'.$pathinfo;
Copy link
Member Author

Choose a reason for hiding this comment

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

do we want to do this? and if we do, should we do the same for the case without RequestContext being set at all?

Copy link

Choose a reason for hiding this comment

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

I hope the question is not for me. I cannot comment on the code because I do not understand it well.
I try to keep away from anything that comes into contact with preparePathInfo() and prepareBaseUrl() methods of Request, because it's a black magic.

Copy link
Member Author

Choose a reason for hiding this comment

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

this is more a question to @lsmith77

Copy link
Member

Choose a reason for hiding this comment

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

I am not deep enough into this PR to really tell either .. @Tobion might know best in general as he knows the entire routing topic really well ..

@sustmi
Copy link

sustmi commented Jan 11, 2016

Hi @dbu . I tried the fix and it works for me.

if ($this->context->getBaseUrl()) {
$uri = $this->context->getBaseUrl().$uri;
$pathinfo = $this->context->getBaseUrl().$pathinfo;
Copy link

Choose a reason for hiding this comment

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

pathinfo is the path without the base url according to CGI spec. so the variable naming reuse is confusing.

@Tobion
Copy link

Tobion commented Jan 20, 2016

The query string handling seems to be missing (which is not that important because it's not used by the routing itself AFAIK, but for consistency and extensebility).

@dbu
Copy link
Member Author

dbu commented Jan 20, 2016 via email

@Tobion
Copy link

Tobion commented Jan 20, 2016

Yes, the pathinfo does not contain the query string. Just add the query string at the end. See https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Request.php#L1067

@Tobion
Copy link

Tobion commented Jan 20, 2016

Otherwise looks good now 👍

@dbu
Copy link
Member Author

dbu commented Jan 21, 2016

i think contrary to other parts, the query parameters are actually used in the create method. but i added them to the url nontheless for completeness. will merge when its green.

as we discussed yesterday, it would be really nice to have a stand alone Request class cleanly separated from HTTP header and other black magic, with a separate RequestBuilder to build request instances from HTTP. i hope for symfony 4 :-)

dbu added a commit that referenced this pull request Jan 21, 2016
fix the edge case of double leading slash when rebuilding request
@dbu dbu merged commit 3eccda0 into master Jan 21, 2016
@lsmith77 lsmith77 removed the wip/poc label Jan 21, 2016
@dbu dbu deleted the fix-edge-case branch January 21, 2016 07:36
}
$uri = $this->context->getScheme().'://'.$host.$uri.$this->context->getQueryString();
Copy link

Choose a reason for hiding this comment

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

this does not work. it's missing the ? before the query string. this is why i linked the exmaple implementation https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Request.php#L1067

Copy link
Member Author

@dbu dbu Jan 21, 2016 via email

Choose a reason for hiding this comment

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

dbu added a commit that referenced this pull request Jan 21, 2016
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.

ChainRouter does not handle URLs starting with two slashes properly
4 participants