?
avatar csthomas
csthomas
9 Oct 2017

Steps to reproduce the issue

Turn off sef.

Modify file to see some debug:

diff --git a/libraries/src/Component/Router/Rules/MenuRules.php b/libraries/src/Component/Router/Rules/MenuRules.php
index e1e7d37ffd..52e7b23b2e 100644
--- a/libraries/src/Component/Router/Rules/MenuRules.php
+++ b/libraries/src/Component/Router/Rules/MenuRules.php
@@ -61,6 +61,7 @@ class MenuRules implements RulesInterface
         */
        public function preprocess(&$query)
        {
+               static $i=0;$i++;$this->router->app->enqueueMessage("$i: " . print_r($query, 1));
                $active = $this->router->menu->getActive();
 
                /**

Expected result

Preprocess method is called only once per link

Actual result

Each build URL called it twice at:
https://github.com/joomla/joomla-cms/blob/staging/libraries/src/Router/SiteRouter.php#L480
and
https://github.com/joomla/joomla-cms/blob/staging/libraries/src/Router/SiteRouter.php#L669

System information (as much as possible)

Joomla 3.8.1

Additional comments

My suggestion is do not call crouter->preprocess() in buildRawRoute() for not legacy routing:

diff --git a/libraries/src/Router/SiteRouter.php b/libraries/src/Router/SiteRouter.php                    
index 702b77414e..2e0d79b20e 100644
--- a/libraries/src/Router/SiteRouter.php
+++ b/libraries/src/Router/SiteRouter.php
@@ -12,6 +12,7 @@ defined('JPATH_PLATFORM') or die;
 
 use Joomla\CMS\Application\CMSApplication;
 use Joomla\CMS\Component\ComponentHelper;
+use Joomla\CMS\Component\Router\RouterBase;
 use Joomla\CMS\Component\Router\RouterInterface;
 use Joomla\CMS\Component\Router\RouterLegacy;
 use Joomla\String\StringHelper;
@@ -477,9 +478,12 @@ class SiteRouter extends Router
 
                $component = preg_replace('/[^A-Z0-9_\.-]/i', '', $query['option']);
                $crouter   = $this->getComponentRouter($component);
-               $query     = $crouter->preprocess($query);
 
-               $uri->setQuery($query);
+               if ($crouter instanceof RouterBase === false)
+               {
+                       $query = $crouter->preprocess($query);
+                       $uri->setQuery($query);
+               }
        }
 
        /**
avatar csthomas csthomas - open - 9 Oct 2017
avatar joomla-cms-bot joomla-cms-bot - labeled - 9 Oct 2017
avatar csthomas csthomas - change - 9 Oct 2017
The description was changed
avatar csthomas csthomas - edited - 9 Oct 2017
avatar csthomas csthomas - change - 16 Oct 2017
The description was changed
avatar csthomas csthomas - edited - 16 Oct 2017
avatar csthomas csthomas - change - 16 Oct 2017
Status New Closed
Closed_Date 0000-00-00 00:00:00 2017-10-16 18:01:59
Closed_By csthomas
avatar csthomas csthomas - close - 16 Oct 2017
avatar csthomas
csthomas - comment - 16 Oct 2017

I prepared a PR #18353

Add a Comment

Login with GitHub to post a comment