Fix SMB storage to not normalize UTF8

This makes sure that even if a NFD file name exists, it is found by the
storage and will be visible to higher layers. Even though the file will
be discarded anyway there, it gives the scanner a chance to display a
warning at least.
This commit is contained in:
Vincent Petry 2016-04-29 11:19:00 +02:00
parent 61203eee04
commit 4326d73ff6
No known key found for this signature in database
GPG Key ID: AF8F9EFC56562186
2 changed files with 9 additions and 14 deletions

View File

@ -100,7 +100,7 @@ class SMB extends \OC\Files\Storage\Common {
* @return string * @return string
*/ */
protected function buildPath($path) { protected function buildPath($path) {
return Filesystem::normalizePath($this->root . '/' . $path); return Filesystem::normalizePath($this->root . '/' . $path, true, false, true);
} }
/** /**

View File

@ -790,11 +790,12 @@ class Filesystem {
* Fix common problems with a file path * Fix common problems with a file path
* *
* @param string $path * @param string $path
* @param bool $stripTrailingSlash * @param bool $stripTrailingSlash whether to strip the trailing slash
* @param bool $isAbsolutePath * @param bool $isAbsolutePath whether the given path is absolute
* @param bool $keepUnicode true to disable unicode normalization
* @return string * @return string
*/ */
public static function normalizePath($path, $stripTrailingSlash = true, $isAbsolutePath = false) { public static function normalizePath($path, $stripTrailingSlash = true, $isAbsolutePath = false, $keepUnicode = false) {
if (is_null(self::$normalizedPathCache)) { if (is_null(self::$normalizedPathCache)) {
self::$normalizedPathCache = new CappedMemoryCache(); self::$normalizedPathCache = new CappedMemoryCache();
} }
@ -818,19 +819,13 @@ class Filesystem {
} }
//normalize unicode if possible //normalize unicode if possible
if (!$keepUnicode) {
$path = \OC_Util::normalizeUnicode($path); $path = \OC_Util::normalizeUnicode($path);
}
//no windows style slashes //no windows style slashes
$path = str_replace('\\', '/', $path); $path = str_replace('\\', '/', $path);
// When normalizing an absolute path, we need to ensure that the drive-letter
// is still at the beginning on windows
$windows_drive_letter = '';
if ($isAbsolutePath && \OC_Util::runningOnWindows() && preg_match('#^([a-zA-Z])$#', $path[0]) && $path[1] == ':' && $path[2] == '/') {
$windows_drive_letter = substr($path, 0, 2);
$path = substr($path, 2);
}
//add leading slash //add leading slash
if ($path[0] !== '/') { if ($path[0] !== '/') {
$path = '/' . $path; $path = '/' . $path;
@ -856,7 +851,7 @@ class Filesystem {
$path = substr($path, 0, -2); $path = substr($path, 0, -2);
} }
$normalizedPath = $windows_drive_letter . $path; $normalizedPath = $path;
self::$normalizedPathCache[$cacheKey] = $normalizedPath; self::$normalizedPathCache[$cacheKey] = $normalizedPath;
return $normalizedPath; return $normalizedPath;