From f85a2bfe9861262aba007ff638948879d4f1a469 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 25 Mar 2016 16:46:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=B7=AF=E7=94=B1=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E5=AE=9A=E4=B9=89=20=E6=94=AF=E6=8C=81=20=20=E5=8F=AF=E9=80=89=E5=8F=98=E9=87=8F=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index 02ec90e5..0db27162 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -599,9 +599,15 @@ class Route $var = []; foreach ($m2 as $key => $val) { // val中定义了多个变量 - if (false !== strpos($val, '<') && preg_match_all('/<(\w+)>/', $val, $matches)) { + if (false !== strpos($val, '<') && preg_match_all('/<(\w+(\??))>/', $val, $matches)) { foreach ($matches[1] as $name) { - $val = str_replace('<' . $name . '>', '(' . $pattern[$name] . ')', $val); + if (strpos($name, '?')) { + // 可选 + $name = substr($name, 0, -1); + $val = str_replace('<' . $name . '?>', '((' . $pattern[$name] . ')?)', $val); + } else { + $val = str_replace('<' . $name . '>', '(' . $pattern[$name] . ')', $val); + } } if (!preg_match('/^' . $val . '$/', $m1[$key])) { return false;