Mvc/Router/Http/Segment.php escapes valid chars #2461

zfbot opened this Issue Sep 28, 2012 · 7 comments


None yet
3 participants

zfbot commented Sep 28, 2012

Jira Information

Original Issue:ZF2-205
Issue Type:Bug
Reporter:Henning Panke


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.

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}}.

zfbot commented Sep 28, 2012

(Originally posted by: DASPRiD on 03/08/12)

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.

zfbot commented Sep 28, 2012

(Originally posted by: Henning Panke on 03/09/12)

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.


zfbot commented Sep 28, 2012

(Originally posted by: DASPRiD on 04/29/12)

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.

zfbot commented Sep 28, 2012

This issue was ported from the ZF2 Jira Issue Tracker at

Known GitHub users mentioned in the original message or comment:

DASPRiD was assigned Sep 28, 2012


DASPRiD commented Sep 28, 2012

There's no acceptable fast solution to escape path specific, thus closing the issue, as it has no malfunctional impact.

DASPRiD closed this Sep 28, 2012


baranga commented Oct 9, 2012

He Ben,
Henning here again. Seen you closed the issue. Just played a bit around and found another way with better performance:
On my pc the implementation is just on around 200% runtime.



baranga commented Oct 9, 2012

Added a pull request with implementation: #2710 zendframework#2710

@weierophinney weierophinney added a commit that referenced this issue Oct 10, 2012

@weierophinney weierophinney Merge branch 'hotfix/2710'
Close #2461
Close #2710
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment