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

Closed
zfbot opened this Issue Sep 28, 2012 · 7 comments

Comments

Projects
None yet
3 participants

zfbot commented Sep 28, 2012

Jira Information

Original Issue:ZF2-205
Issue Type:Bug
Reporter:Henning Panke
Created:03/08/12
Assignee:DASPRiD
Components:Zend\Mvc\Router

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

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.

Cheers,
Henning

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
http://framework.zend.com/issues/browse/ZF2-205

Known GitHub users mentioned in the original message or comment:
@DASPRiD

DASPRiD was assigned Sep 28, 2012

Member

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

Contributor

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: https://gist.github.com/3857351
On my pc the implementation is just on around 200% runtime.

Cheers,
Henning

Contributor

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
e76ac6c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment