Skip to content

Commit

Permalink
MDL-83293 core: Fix path separator when guessing the base path
Browse files Browse the repository at this point in the history
Ensure that path separator for the script when guessing the base path
uses forward slash instead of the OS' directory separator.
(e.g. "\" in Windows)
  • Loading branch information
junpataleta committed Oct 2, 2024
1 parent fdc73d8 commit f8184f0
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/classes/router.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,17 @@ protected function guess_basepath(): string {
// Moodle is not guaranteed to exist at the domain root.
// Strip out the current script.
$scriptroot = parse_url($CFG->wwwroot, PHP_URL_PATH);
$scriptfile = str_replace(
realpath($CFG->dirroot),
'',
realpath($_SERVER['SCRIPT_FILENAME']),
);
// Replace occurrences of backslashes with forward slashes, especially on Windows.
$scriptfile = str_replace('\\', '/', $scriptfile);
$relativeroot = sprintf(
'%s%s',
$scriptroot,
str_replace(
realpath($CFG->dirroot),
'',
realpath($_SERVER['SCRIPT_FILENAME']),
),
$scriptfile,
);

// The server is not configured to rewrite unknown requests to automatically use the router.
Expand Down

0 comments on commit f8184f0

Please sign in to comment.