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]; }