MDL-83293 core: Fix path separator when guessing the base path

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)
This commit is contained in:
Jun Pataleta 2024-10-03 06:43:20 +08:00
parent 0eacab846e
commit f173a7026a
No known key found for this signature in database
GPG Key ID: F83510526D99E2C7

View File

@ -92,14 +92,17 @@ class router {
// 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.