mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
MDL-62251 Privacy: Fix get_path() and get_full_path() bug in Windows
This commit is contained in:
parent
4dfafed5d9
commit
44efefcbeb
@ -272,7 +272,9 @@ class moodle_content_writer implements content_writer {
|
||||
// Join the directory together with the name.
|
||||
$filepath = implode(DIRECTORY_SEPARATOR, $path) . DIRECTORY_SEPARATOR . $name;
|
||||
|
||||
return preg_replace('@' . DIRECTORY_SEPARATOR . '+@', DIRECTORY_SEPARATOR, $filepath);
|
||||
// To use backslash, it must be doubled ("\\\\" PHP string).
|
||||
$separator = str_replace('\\', '\\\\', DIRECTORY_SEPARATOR);
|
||||
return preg_replace('@(' . $separator . '|/)+@', $separator, $filepath);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -291,7 +293,9 @@ class moodle_content_writer implements content_writer {
|
||||
// Join the directory together with the name.
|
||||
$filepath = implode(DIRECTORY_SEPARATOR, $path);
|
||||
|
||||
return preg_replace('@' . DIRECTORY_SEPARATOR . '+@', DIRECTORY_SEPARATOR, $filepath);
|
||||
// To use backslash, it must be doubled ("\\\\" PHP string).
|
||||
$separator = str_replace('\\', '\\\\', DIRECTORY_SEPARATOR);
|
||||
return preg_replace('@(' . $separator . '|/)+@', $separator, $filepath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1162,12 +1162,18 @@ class moodle_content_writer_test extends advanced_testcase {
|
||||
if (null === $subcontext) {
|
||||
$rcm = $rc->getMethod('get_context_path');
|
||||
$rcm->setAccessible(true);
|
||||
return $rcm->invoke($writer);
|
||||
$path = $rcm->invoke($writer);
|
||||
} else {
|
||||
$rcm = $rc->getMethod('get_path');
|
||||
$rcm->setAccessible(true);
|
||||
return $rcm->invoke($writer, $subcontext, $name);
|
||||
$path = $rcm->invoke($writer, $subcontext, $name);
|
||||
}
|
||||
|
||||
// PHPUnit uses mikey179/vfsStream which is a stream wrapper for a virtual file system that uses '/'
|
||||
// as the directory separator.
|
||||
$path = str_replace(DIRECTORY_SEPARATOR, '/', $path);
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user