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

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.

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

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.

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