From 74b612715c615cbcd0ea2086604b47c6ac92fd18 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Sun, 13 Dec 2020 22:31:05 +0900 Subject: [PATCH] Fix #1470 RSS not working due to new Router --- common/framework/router.php | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/common/framework/router.php b/common/framework/router.php index 23063f036..efc34c28e 100644 --- a/common/framework/router.php +++ b/common/framework/router.php @@ -16,16 +16,16 @@ class Router 'vars' => ['document_srl' => 'int'], 'priority' => 0, ), - '$mid' => array( - 'regexp' => '#^(?[a-zA-Z0-9_-]+)/?$#', - 'vars' => ['mid' => 'any'], - 'priority' => 0, - ), '$act' => array( 'regexp' => '#^(?rss|atom)$#', 'vars' => ['act' => 'word'], 'priority' => 0, ), + '$mid' => array( + 'regexp' => '#^(?[a-zA-Z0-9_-]+)/?$#', + 'vars' => ['mid' => 'any'], + 'priority' => 0, + ), '$mid/$document_srl' => array( 'regexp' => '#^(?[a-zA-Z0-9_-]+)/(?[0-9]+)$#', 'vars' => ['mid' => 'any', 'document_srl' => 'int'], @@ -54,6 +54,14 @@ class Router ), ); + /** + * List of legacy URLs that should not be treated as prefixes. + */ + protected static $_except_prefixes = array( + 'rss' => true, + 'atom' => true, + ); + /** * List of legacy modules whose URLs should not be shortened. */ @@ -138,7 +146,7 @@ class Router } // Try to detect the prefix. This might be $mid. - if ($rewrite_level >= 2 && preg_match('#^([a-zA-Z0-9_-]+)(?:/(.*))?$#s', $url, $matches)) + if ($rewrite_level >= 2 && preg_match('#^([a-zA-Z0-9_-]+)(?:/(.*))?$#s', $url, $matches) && !isset(self::$_except_prefixes[$matches[1]])) { // Separate the prefix and the internal part of the URL. $prefix = $matches[1]; @@ -162,11 +170,11 @@ class Router if ($action_info) { // Try the index action. - if ($internal_url === '' && !isset($args['act']) && $action_info->default_index_act) + if ($prefix_type === 'mid' && $internal_url === '' && !isset($args['act']) && $action_info->default_index_act) { $allargs = array_merge($args, [$prefix_type => $prefix]); $result->module = $module_name; - $result->mid = $prefix_type === 'mid' ? $prefix : ''; + $result->mid = $prefix; $result->args = $allargs; return $result; } @@ -247,7 +255,7 @@ class Router $result->forwarded = true; $result->args = $allargs; return $result; - } + } } }