From f913450da88512dceb15760c5780a060225c88bc Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 7 Sep 2016 12:34:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E4=B9=89=E4=BA=86=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E8=A7=84=E5=88=99=E7=9A=84URL=E5=8E=9F=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E7=A6=81=E6=AD=A2=E8=AE=BF=E9=97=AE=20=E6=94=B9=E8=BF=9B?= =?UTF-8?q?=E5=88=86=E7=BB=84=E8=B7=AF=E7=94=B1=E7=9A=84=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lang/zh-cn.php | 1 + library/think/Route.php | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/lang/zh-cn.php b/lang/zh-cn.php index b93092e2..db43a1c4 100644 --- a/lang/zh-cn.php +++ b/lang/zh-cn.php @@ -61,4 +61,5 @@ return [ 'cache write error' => '缓存写入失败', 'sae mc write error' => 'SAE mc 写入错误', 'route name not exists' => '路由标识不存在(或参数不够)', + 'invalid request' => '非法请求', ]; diff --git a/library/think/Route.php b/library/think/Route.php index a00e56f1..62cb4790 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -422,6 +422,8 @@ class Route } $vars = self::parseVar($key); $item[] = ['rule' => $key, 'route' => $route, 'var' => $vars, 'option' => $options, 'pattern' => $patterns]; + // 设置路由标识 + self::$name[$route][] = [$key, $vars, self::$domain]; } self::$rules['*'][$name] = ['rule' => $item, 'route' => '', 'var' => [], 'option' => $option, 'pattern' => $pattern]; } @@ -1170,6 +1172,9 @@ class Route self::parseUrlParams(empty($path) ? '' : implode('/', $path)); // 封装路由 $route = [$module, $controller, $action]; + if (isset(self::$name[implode($depr, $route)])) { + throw new HttpException(404, 'invalid request:' . $url); + } } return ['type' => 'module', 'module' => $route]; }