From e0491932b534ce4fcd46b6bc2d430d9596ac962f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 25 Sep 2016 11:34:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=B7=AF=E7=94=B1=E6=B7=B7?= =?UTF-8?q?=E5=90=88=E5=8F=98=E9=87=8F=E4=B8=AD=E5=AD=98=E5=9C=A8=E5=8F=AF?= =?UTF-8?q?=E9=80=89=E5=8F=98=E9=87=8F=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index 384ab2dc..339e4903 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1236,17 +1236,20 @@ class Route foreach ($matches[1] as $name) { if (strpos($name, '?')) { $name = substr($name, 0, -1); - $replace[] = '(' . (isset($pattern[$name]) ? $pattern[$name] : '\w+') . '?)'; + $replace[] = '(' . (isset($pattern[$name]) ? $pattern[$name] : '\w+') . ')?'; } else { $replace[] = '(' . (isset($pattern[$name]) ? $pattern[$name] : '\w+') . ')'; } $value[] = $name; } $val = str_replace($matches[0], $replace, $val); - if (preg_match('/^' . $val . '$/', $m1[$key], $match)) { + if (preg_match('/^' . $val . '$/', isset($m1[$key]) ? $m1[$key] : '', $match)) { array_shift($match); - $match = array_slice($match, 0, count($value)); - $var = array_merge($var, array_combine($value, $match)); + foreach ($value as $k => $name) { + if (isset($match[$k])) { + $var[$name] = $match[$k]; + } + } continue; } else { return false;