Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5083a35

Browse files
committed
bug #18352 [Debug] Fix case sensitivity checks (nicolas-grekas)
This PR was merged into the 2.7 branch. Discussion ---------- [Debug] Fix case sensitivity checks | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | yes | Deprecations? | no | Tests pass? | yes | Fixed tickets | #18344 | License | MIT | Doc PR | - Commits ------- 7336177 [Debug] Fix case sensitivity checks
2 parents 03c28e4 + 7336177 commit 5083a35

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/Symfony/Component/Debug/DebugClassLoader.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,25 @@ public function __construct($classLoader)
5151
}
5252

5353
if (!isset(self::$caseCheck)) {
54-
if(!file_exists(strtolower(__FILE__))) {
54+
$file = file_exists(__FILE__) ? __FILE__ : rtrim(realpath('.'), DIRECTORY_SEPARATOR);
55+
$i = strrpos($file, DIRECTORY_SEPARATOR);
56+
$dir = substr($file, 0, 1 + $i);
57+
$file = substr($file, 1 + $i);
58+
$test = strtoupper($file) === $file ? strtolower($file) : strtoupper($file);
59+
$test = realpath($dir.$test);
60+
61+
if (false === $test || false === $i) {
5562
// filesystem is case sensitive
5663
self::$caseCheck = 0;
57-
} elseif(realpath(strtolower(__FILE__)) === __FILE__) {
58-
// filesystem is not case sensitive
64+
} elseif (substr($test, -strlen($file)) === $file) {
65+
// filesystem is case insensitive and realpath() normalizes the case of characters
5966
self::$caseCheck = 1;
60-
} else {
61-
// filesystem is not case sensitive AND realpath() fails to normalize case
67+
} elseif (false !== stripos(PHP_OS, 'darwin')) {
68+
// on MacOSX, HFS+ is case insensitive but realpath() doesn't normalize the case of characters
6269
self::$caseCheck = 2;
70+
} else {
71+
// filesystem case checks failed, fallback to disabling them
72+
self::$caseCheck = 0;
6373
}
6474
}
6575
}

0 commit comments

Comments
 (0)