Skip to content

Commit

Permalink
fixed utf-8 pattern in router option
Browse files Browse the repository at this point in the history
  • Loading branch information
zoghal committed Dec 2, 2012
1 parent c1551d9 commit d5283af
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Cake/Routing/Route/CakeRoute.php
Expand Up @@ -182,7 +182,7 @@ public function parse($url) {
if (!$this->compiled()) {
$this->compile();
}
if (!preg_match($this->_compiledRoute, $url, $route)) {
if (!preg_match($this->_compiledRoute, urldecode($url), $route)) {
return false;
}
foreach ($this->defaults as $key => $val) {
Expand Down
24 changes: 24 additions & 0 deletions lib/Cake/Test/Case/Routing/Route/CakeRouteTest.php
Expand Up @@ -880,4 +880,28 @@ public function testParseTrailingUTF8() {
$this->assertEquals($expected, $result);
}


/**
* test that utf-8 patterns work for :section
*
* @return void
*/
public function testUTF8PatternOnSection() {
$route = new CakeRoute(
'/:section',
array('plugin' => 'blogs', 'controller' => 'posts' , 'action' => 'index' ),
array(
'persist' => array('section'),
'section' => 'آموزش|weblog'
)
);

$result = $route->parse('/%D8%A2%D9%85%D9%88%D8%B2%D8%B4');
$expected = array('section' => 'آموزش', 'plugin' => 'blogs', 'controller' => 'posts', 'action' => 'index', 'pass' => array(), 'named' => array());
$this->assertEquals($expected, $result);

$result = $route->parse('/weblog');
$expected = array('section' => 'weblog', 'plugin' => 'blogs', 'controller' => 'posts', 'action' => 'index', 'pass' => array(), 'named' => array());
$this->assertEquals($expected, $result);
}
}

8 comments on commit d5283af

@lemon-lime
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This modification breaks routes that include a urlencoded '/' in a parameter.

@markstory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is unfortunate, I would think utf8 characters are more likely to be found in path segments over encoded / 's.

@zoghal
Copy link
Contributor Author

@zoghal zoghal commented on d5283af Mar 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lemon-lime For more reviews, please tell me an example of a url that failed

@JelmerD
Copy link

@JelmerD JelmerD commented on d5283af Jan 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markstory do you have an example of an url that includes utf8 characters? I'm not quite sure what you mean by this. I spent an entire afternoon trying to solve why my urlencoded parameter wouldn't get through correctly, so I'm now kinda curious to understand why it has to behave like this.

@markstory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JelmerD URLs with non-ascii characters, like in the test. If this code is causing a problem please open an issue. Commit comments are easy to lose track of and find again.

@JelmerD
Copy link

@JelmerD JelmerD commented on d5283af Jan 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markstory Edited:

I see. So I kinda understand why you're now doing this, but I think it this is not the behaviour we want because in my opinion it doesn't make sense.

I will open a ticket for discussion. Because a base64-encoded string might contain a /. So if you parse a string like this, which should be perfectly fine, it fails the request, because it now splits this one parameter into two.

** kind of works, as long as this base64 encoded parameter is at the end. But what if I parse 2 base64 encoded params? Or a base64 encoded param followed by another parameter. That's now impossible.

@zoghal
Copy link
Contributor Author

@zoghal zoghal commented on d5283af Jan 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markstory do you have an example of an url that includes utf8 characters?.

You can find many examples on this website.

@JelmerD
Copy link

@JelmerD JelmerD commented on d5283af Jan 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a bug report #15269

Please sign in to comment.