From 11923064810be47ed24888efcd53a36674e83fd2 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Mon, 3 Jun 2013 08:59:41 +0200 Subject: [PATCH] improved UrlManager RESTful syntax regex --- framework/yii/web/UrlManager.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/framework/yii/web/UrlManager.php b/framework/yii/web/UrlManager.php index d7135c5..44c63c5 100644 --- a/framework/yii/web/UrlManager.php +++ b/framework/yii/web/UrlManager.php @@ -45,11 +45,11 @@ class UrlManager extends Component * * For RESTful routing the mentioned shortcut format also allows you to specify the * [[UrlRule::verb|HTTP verb]] that the rule should apply for. - * You can do that by prepending it to the pattern, separated by a space. + * You can do that by prepending it to the pattern, separated by space. * For example, `'PUT post/' => 'post/update'`. * You may specify multiple verbs by separating them with comma * like this: `'POST,PUT post/index' => 'post/create'`. - * The supported verbs in the shortcut format are: GET, POST, PUT and DELETE. + * The supported verbs in the shortcut format are: GET, HEAD, POST, PUT and DELETE. * Note that [[UrlRule::mode|mode]] will be set to PARSING_ONLY when specifying verb in this way * so you normally would not specify a verb for normal GET request. * @@ -142,13 +142,10 @@ class UrlManager extends Component $rule = array( 'route' => $rule, ); - if (($pos = strpos($key, ' ')) !== false) { - $verbs = substr($key, 0, $pos); - if (preg_match('/^((GET|POST|PUT|DELETE),?)*$/', $verbs, $matches)) { - $rule['verb'] = explode(',', $verbs); - $rule['mode'] = UrlRule::PARSING_ONLY; - $key = substr($key, $pos + 1); - } + if (preg_match('/^((?:(GET|HEAD|POST|PUT|DELETE),)*(GET|HEAD|POST|PUT|DELETE))\s+(.*)$/', $key, $matches)) { + $rule['verb'] = explode(',', $matches[1]); + $rule['mode'] = UrlRule::PARSING_ONLY; + $key = $matches[4]; } $rule['pattern'] = $key; }