Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.2. Backport: Normalize paths in autoloader maps #3222

Merged
merged 1 commit into from Nov 3, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 7 additions & 13 deletions library/core/class.autoloader.php
Expand Up @@ -1068,26 +1068,20 @@ public function mapType() {
}

/**
* Fix path with backslash for Windows OS.
* Normalize paths
*
* Check to see if the path is not empty and if it is not in a form of drive: then replace any "\" with "/" to avoid
* the parse_fn_file bug and it also further check to see if it has only one "/" and the OS is "WIN" then it will prepend "/"
* in front of the path so it has the correct file path.
* Replaces any "\" with "/" and prepends another slash to a single leading slash.
*
* @param string $path
* @return string
*/
function fixBackSlash($path) {
if (!empty($path) && !preg_match('`^[a-z]:`i', $path)) {
// Convert to slash to avoid parse_in_file create array with missing backslash.
$path = str_replace("\\", "/", $path);

// If there is only 1 slash, add another to have a valid network path.
if (preg_match('`^/[^/]`', $path) && stripos(PHP_OS, 'win') === 0) {
$path = "/".$path;
}
// Convert to slash to avoid parse_in_file create array with missing backslash.
$path = str_replace('\\', '/', $path);
// If there is only 1 slash, add another to have a valid network path.
if (preg_match('`^/[^/]`', $path) && stripos(PHP_OS, 'win') === 0) {
$path = '/'.$path;
}

return $path;
}

Expand Down