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

[Bug] urlencoded slashes in routing parameters #4338

Closed
wants to merge 4 commits into from
Closed

[Bug] urlencoded slashes in routing parameters #4338

wants to merge 4 commits into from

Conversation

Artistan
Copy link
Contributor

@Artistan Artistan commented May 4, 2014

Routing

Current routes do not allow for urlencoded slashes in the paths. This is problematic when trying to create ecommerce solutions with partnumbers in the routes since many part numbers have slashes in them. There are also quite a few manufacturers with slashes in their names and or brands. This commit provides the functionality to allow an uri to have encoded slashes, and other characters, in the routes and also to create routes with those parameters. An example url may be...

https://stage.test.com/part/Cisco%20Systems%2C%20Inc/CISCO2851-SRST%2FK9

thank you!

Artistan added 3 commits May 4, 2014 14:17
the raw urlencode on full path did not allow encoded slashes in the url parameters
encode the parameters when creating routes, not the full url! allows slashes in parameters
allow parsing the parameters out of route before decoding.
this will allow encoded slashes in the parameters.
did not mean to remove the new force route.
@Artistan
Copy link
Contributor Author

Artistan commented May 4, 2014

$route = new Illuminate\Routing\Route(array('GET'), 'foo/bar/åαф/{baz}', array('as' => 'foobarbaz'));
this is a terrible test.
the router should not have to create valid urls for random text in a route.
parameters, yes, but people should make valid urls. dang.

@taylorotwell
Copy link
Member

Honestly this is kind of hack for your use case. Just don't use slashes in the URLs. Use something else.

@Artistan
Copy link
Contributor Author

Artistan commented May 4, 2014

mind if I finish my request before you close this?

@ghost
Copy link

ghost commented May 5, 2014

how is this a hack to allow valid urlencoded characters?

@Artistan
Copy link
Contributor Author

Artistan commented May 6, 2014

Thank you for your support :)
(artistan/urlencode) [https://github.com/Artistan/Urlencode] [https://packagist.org/packages/artistan/urlencode]

@pilot911
Copy link
Contributor

Strange solution Taylor. We need for autoencoding router parameters.

@Artistan
Copy link
Contributor Author

Agreed pilot!
We have been using my package to override the routing of laravel to allow for this more robust routing option. Not sure why it was unencoding the url before exploding the parameters, but this package makes it work I assumed it would...

(artistan/urlencode) [https://github.com/Artistan/Urlencode] [https://packagist.org/packages/artistan/urlencode]

Basically all it overrides in routing is to explode the url before unencoding the parameters.

@ameenross
Copy link
Contributor

The regex Symfony uses for parts of a path is [^/]+. I don't think it does urldecode before that either. Laravel actually violates the RFC, as the HEX variants of reserved characters (/ is a reserved char) do NOT mean the same as their unencoded variant.

@panzer-planet
Copy link
Contributor

This is still broken and makes passing base64 encoded data in the URL impossible in Laravel. For the 80% use case indeed.

@Artistan
Copy link
Contributor Author

@taylorotwell stated "Just don't use slashes in the URLs. " -- LMAO.
[artistan/urlencode] (https://github.com/Artistan/Urlencode) -- this package worked for me.

@Artistan
Copy link
Contributor Author

basically it decodes the path BEFORE splitting it into parameters and that is why encoded slashes affect the parameters.

@csga5000
Copy link

@panzer-planet While I'd really like to see this fixed, why wouldn't base64 work? URL encoding uses % and base 64 doesn't? So there's no way a base64 string would produce a %2F.

If I'm missing something, let me know and I'll update the issue I just created. Might as well spam them with another issue since they're ignoring this one. Cause this is literally retarded. There is NO reason laravel should be urldecoding the URL before you do routing.

@ameenross
Copy link
Contributor

@csga5000 It's not because base64 uses %, but because base64 uses /. Since you don't want the slash to cut up the URL into parts, you need to urlencode the base64 string. That results into %2F, and that decodes incorrectly, making your "fix" of URL encoding irrelevant.

@csga5000
Copy link

@ameenross Oh, right, I figured I was missing something. Thanks

@ameenross
Copy link
Contributor

You're welcome.

Also of interest: alternative base64 encoding, [A-Za-z0-9-_] more suited for URLs: https://tools.ietf.org/html/rfc4648#page-7

@alcaitiff
Copy link

alcaitiff commented Dec 27, 2019

@csga5000 and @Artistan I changed the Artistan/Urlencode to work on Laravel 5.

You can get it here https://github.com/alcaitiff/laravel-urlencode

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.

7 participants