From a6318436c20a1b038cb256c569814400dc529835 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Fri, 19 Jun 2020 11:33:21 +0900 Subject: [PATCH] Adjust argument priority --- classes/context/Context.class.php | 28 +++++++++++++--------------- common/framework/router.php | 12 ++++++------ 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/classes/context/Context.class.php b/classes/context/Context.class.php index dc00620b9..6e356dcf8 100644 --- a/classes/context/Context.class.php +++ b/classes/context/Context.class.php @@ -1201,7 +1201,16 @@ class Context */ public static function setRequestArguments(array $router_args = []) { - foreach($router_args ?: $_REQUEST as $key => $val) + $request_args = $_SERVER['REQUEST_METHOD'] === 'GET' ? $_GET : $_POST; + if (count($router_args)) + { + foreach ($router_args as $key => $val) + { + $request_args[$key] = $val; + } + } + + foreach($request_args as $key => $val) { if($val === '' || isset(self::$_reserved_keys[$key]) || self::get($key)) { @@ -1210,18 +1219,7 @@ class Context $key = escape($key); $val = self::_filterRequestVar($key, $val); - $set_to_vars = $router_args ? true : false; - - if($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET[$key])) - { - $set_to_vars = true; - } - elseif($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST[$key])) - { - $set_to_vars = true; - } - - self::set($key, $val, $set_to_vars); + self::set($key, $val, true); } // Set deprecated request parameters. @@ -1245,7 +1243,7 @@ class Context foreach((array)$params as $key => $val) { - if (isset($router_args[$key])) + if (isset($request_args[$key])) { continue; } @@ -1260,7 +1258,7 @@ class Context parse_str($GLOBALS['HTTP_RAW_POST_DATA'], $params); foreach($params as $key => $val) { - if (isset($router_args[$key])) + if (isset($request_args[$key])) { continue; } diff --git a/common/framework/router.php b/common/framework/router.php index ca667e0f4..2ef697aa8 100644 --- a/common/framework/router.php +++ b/common/framework/router.php @@ -145,7 +145,7 @@ class Router if (preg_match($regexp, $internal_url, $matches)) { $matches = array_filter($matches, 'is_string', \ARRAY_FILTER_USE_KEY); - $allargs = array_merge(['mid' => $prefix, 'act' => $action], $matches, $args); + $allargs = array_merge($args, $matches, ['mid' => $prefix, 'act' => $action]); $result->module = $module_name; $result->mid = $prefix; $result->act = $action; @@ -161,7 +161,7 @@ class Router if (preg_match($regexp, $internal_url, $matches)) { $matches = array_filter($matches, 'is_string', \ARRAY_FILTER_USE_KEY); - $allargs = array_merge(['mid' => $prefix, 'act' => $action[1]], $matches, $args); + $allargs = array_merge($args, $matches, ['mid' => $prefix, 'act' => $action[1]]); $result->module = $action[0]; $result->mid = $prefix; $result->act = $action[1]; @@ -174,7 +174,7 @@ class Router // Try the generic mid/act pattern. if (preg_match('#^[a-zA-Z0-9_]+$#', $internal_url)) { - $allargs = array_merge(['mid' => $prefix, 'act' => $internal_url], $args); + $allargs = array_merge($args, ['mid' => $prefix, 'act' => $internal_url]); $result->mid = $prefix; $result->act = $internal_url; $result->forwarded = true; @@ -185,7 +185,7 @@ class Router // If the module defines a 404 error handler, call it. if ($internal_url && isset($action_info->error_handlers[404])) { - $allargs = array_merge(['mid' => $prefix, 'act' => $action_info->error_handlers[404]], $args); + $allargs = array_merge($args, ['mid' => $prefix, 'act' => $action_info->error_handlers[404]]); $result->module = $module_name; $result->mid = $prefix; $result->act = $action_info->error_handlers[404]; @@ -205,7 +205,7 @@ class Router if (preg_match($regexp, $url, $matches)) { $matches = array_filter($matches, 'is_string', \ARRAY_FILTER_USE_KEY); - $allargs = array_merge(['act' => $action[1]], $matches, $args); + $allargs = array_merge($args, $matches, ['act' => $action[1]]); $result->module = $action[0]; $result->act = $action[1]; $result->forwarded = true; @@ -221,7 +221,7 @@ class Router if (preg_match($route_info['regexp'], $url, $matches)) { $matches = array_filter($matches, 'is_string', \ARRAY_FILTER_USE_KEY); - $allargs = array_merge($route_info['extra_vars'] ?? [], $matches, $args); + $allargs = array_merge($args, $matches, $route_info['extra_vars'] ?? []); $result->module = $allargs['module'] ?? ''; $result->mid = $allargs['mid'] ?: ''; $result->act = $allargs['act'] ?: '';