Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-84543

New router seems to clash with $CFG->wwwroot "no slash" requirement

XMLWordPrintable

      On a fresh Moodle 4.5.2 install, accessing Moodle without the new router feature works as intended but trying to use it leads to this error :

      Fatal error: Uncaught TypeError: core\router::guess_basepath(): Return value must be of type string, null returned in /appli/moodle/www/lib/classes/router.php:115
      Stack trace:
        #0 /appli/moodle/www/lib/classes/router.php(79): core\router->guess_basepath()
        #1 /appli/moodle/www/lib/php-di/php-di/src/Definition/Resolver/ObjectCreator.php(129): core\router->__construct()
        #2 /appli/moodle/www/lib/php-di/php-di/src/Definition/Resolver/ObjectCreator.php(56): DI\Definition\Resolver\ObjectCreator->createInstance()
        #3 /appli/moodle/www/lib/php-di/php-di/src/Definition/Resolver/ResolverDispatcher.php(60): DI\Definition\Resolver\ObjectCreator->resolve()
        #4 /appli/moodle/www/lib/php-di/php-di/src/Container.php(353): DI\Definition\Resolver\ResolverDispatcher->resolve()
        #5 /appli/moodle/www/lib/php-di/php-di/src/Container.php(136): DI\Container->resolveDefinition()
        #6 /appli/moodle/www/lib/classes/di.php(62): DI\Container->get()
        #7 /appli/moodle/www/r.php(54): core\di::get()
        #8 {main} thrown in /appli/moodle/www/lib/classes/router.php on line 115

      This seems to be caused by line 94 of lib/classes/router.php :

          /**
           * Guess the basepath for the Router.
           *
           * @return string
           */
          protected function guess_basepath(): string {
              global $CFG;        // Moodle is not guaranteed to exist at the domain root.
              // Strip out the current script.
              $scriptroot = parse_url($CFG->wwwroot, PHP_URL_PATH);  //    <--- This one (L94)
              
              // --- redacted some more string processing ---
              
              return $scriptroot;
          } 

      The function "parse_url" returns null because there is no "path part" in $CFG->wwwroot when Moodle is accessed directly at the root. I suspect it doesn't create an issue when Moodle is accessed via a sub-path since the sub-path would be returned instead of null.

      Adding a trailing slash to the wwwroot to make parse_url not return null obviously causes the wwwrootslash error.

            dobedobedoh Andrew Lyons
            RémiLab Rémi Labergère
            Meirza Meirza
            Jun Pataleta Jun Pataleta
            CiBoT CiBoT
            Votes:
            2 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 18 minutes
                18m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.