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

[HttpFoundation] Fix request uri when it starts with double slashes #29494

Merged
merged 1 commit into from Jan 5, 2019

Conversation

alquerci
Copy link
Contributor

@alquerci alquerci commented Dec 6, 2018

Q A
Branch? 3.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #29478
License MIT
Doc PR ~

When the REQUEST_URI starts with a slash no need to parse_url(). However to keep the same behaviour regarding the fragment we need to add a logic to remove it. While parse_url() handle all cases itself.

@alquerci alquerci changed the base branch from master to 3.4 December 6, 2018 20:56
@alquerci alquerci changed the title [HttpFoundation] Fix prepare request uri when the uri is leading with double slashes [HttpFoundation] Fix prepare request uri when it starts with double slashes Dec 6, 2018
@alquerci alquerci changed the title [HttpFoundation] Fix prepare request uri when it starts with double slashes [WIP] [HttpFoundation] Fix prepare request uri when it starts with double slashes Dec 7, 2018
@alquerci alquerci changed the title [WIP] [HttpFoundation] Fix prepare request uri when it starts with double slashes [HttpFoundation] Fix prepare request uri when it starts with double slashes Dec 7, 2018
@alquerci alquerci force-pushed the issue-29478 branch 2 times, most recently from bfe7d4c to c2b69ef Compare December 8, 2018 16:06
@alquerci alquerci changed the title [HttpFoundation] Fix prepare request uri when it starts with double slashes [HttpFoundation] Fix request uri when it starts with double slashes Dec 8, 2018
@alquerci alquerci force-pushed the issue-29478 branch 2 times, most recently from efe0e35 to 99151e4 Compare December 8, 2018 17:54
@chalasr chalasr added this to the 3.4 milestone Dec 9, 2018
@alquerci alquerci force-pushed the issue-29478 branch 2 times, most recently from 95e9fe0 to 8a7707e Compare December 9, 2018 19:36
@alquerci
Copy link
Contributor Author

alquerci commented Dec 9, 2018

All code review notes answered by a code modification and the branch has been rebased and squashed.

@danijelk
Copy link

Maybe extract the if( empty $requestUri string ) to jump over the if/else, unless you actually want to send an empty string into parse_url()? Just micro optimizations. I tested it with our setup and it worked well.

@alquerci
Copy link
Contributor Author

@danijelk Thank you for your feedback.

On the majority of cases REQUEST_URI starts with a slash. The parse_url() usage is just to handle an edge case.

Your idea is good in order to skip null and empty strings. However, it is a bit overkill regarding the occurrence of this case while parse_url() return an empty path without an huge performance impact.

So to keep the code simple (as we cannot use here an early return) I think that this micro optimization adds useless complexity.

@nicolas-grekas Do you think that we can turn this PR as Reviewed status?

@nicolas-grekas
Copy link
Member

Is there a way to keep existing tests the same?
When tests change too much it raises a red flag because it means a regression is possible.
Please reduce the diff to the strict minimum to ease the work of reviewers.

@alquerci
Copy link
Contributor Author

alquerci commented Dec 12, 2018

Is there a way to keep existing tests the same?

Yes for sure. I can revert them.

@nicolas-grekas FYI: Tests has been refactored on this commit 95e9fe0 then squashed.

Its tests has been added on #29256.

cc @thomasbisignani

Copy link

@Dylan-DutchAndBold Dylan-DutchAndBold left a comment

Choose a reason for hiding this comment

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

Isn't this guy's solution where he is just using the parse_url function correctly, much more obvious and readable? a3cbb65

@nicolas-grekas
Copy link
Member

@Dylan-DutchAndBold it's not: see how many tests this "solution" breaks.

@Dylan-DutchAndBold
Copy link

@Dylan-DutchAndBold it's not: see how many tests this "solution" breaks.

You're right, missed that, didn't get what you meant by your original comment at first.

@fabpot
Copy link
Member

fabpot commented Jan 5, 2019

Thank you @alquerci.

@fabpot fabpot merged commit cf850c1 into symfony:3.4 Jan 5, 2019
fabpot added a commit that referenced this pull request Jan 5, 2019
…e slashes (alquerci)

This PR was merged into the 3.4 branch.

Discussion
----------

[HttpFoundation] Fix request uri when it starts with double slashes

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #29478
| License       | MIT
| Doc PR        | ~

When the `REQUEST_URI` starts with a slash no need to `parse_url()`. However to keep the same behaviour regarding the fragment we need to add a logic to remove it. While `parse_url()` handle all cases itself.

Commits
-------

cf850c1 [HttpFoundation] Fix request uri when it starts with double slashes
@alquerci alquerci deleted the issue-29478 branch January 5, 2019 23:36
This was referenced Jan 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet