ZF2-205: Mvc/Router/Http/Segment.php escapes valid chars

Issue Type: Bug Created: 2012-03-08T15:45:18.000+0000 Last Updated: 2012-10-08T20:16:37.000+0000 Status: Closed Fix version(s): Reporter: Henning Panke (henning.panke) Assignee: Ben Scholzen (dasprid) Tags: - Zend\Mvc\Router

Related issues: Attachments: - path_segment_encode.php


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??

RFC 3986 allows much more chars in path segments.

<pre class="highlight">
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.


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:

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.