ZF2-205: Mvc/Router/Http/Segment.php escapes valid chars
Description
Mvc/Router/Http/Segment.php escapes valid segment chars by using urlencode.
urlencode/urldecode and rawurlencode/rawurldecode escapes more chars than necessary. These functions return ??a string in which all non-alphanumeric characters except -_. have been replaced?? http://php.net/manual/en/function.urlencode.php
RFC 3986 allows much more chars in path segments. http://tools.ietf.org/html/rfc3986#appendix-A
use Zend\Mvc\Router\Http\Segment;
$segment = new Segment('/:dada');
$rendered = $segment->assemble(array('dada'=>'Hello World!'));
echo $rendered;
This should return {{/Hello World!}} but returns instead {{/Hello+World%21}}.
Comments
Posted by Ben Scholzen (dasprid) on 2012-03-08T17:20:48.000+0000
You are right, [raw]urlencode() works on the smallest allowed subset (which doesn't break anything tho). We could introduce a path-specific url encoder (probably in Zend\Uri), but I'd have to benchmark the performance first. This is actually only relevant for encoding, not for decoding, as [raw]urldecode() works just fine.
About your example: a space is still not allowed in URIs.
Posted by Henning Panke (henning.panke) on 2012-03-09T14:12:34.000+0000
He Ben, yep, i missed the whitespace, sorry.
I attached a simple benchmark with some solutions. Maybe this helps you to build a acceptable implementation.
Cheers, Henning
Posted by Ben Scholzen (dasprid) on 2012-04-29T10:20:16.000+0000
All those solutions are pretty slow compared to [raw]urlencode(). I have to see if there is a method which does not yield this problem, else I'd have to close this issue.
Posted by Ralph Schindler (ralph) on 2012-10-08T20:16:37.000+0000
This issue has been closed on Jira and moved to GitHub for issue tracking. To continue following the resolution of this issues, please visit: https://github.com/zendframework/zf2/issues/2461