Skip to content

Commit

Permalink
Fix SMB storage to not normalize UTF8
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Vincent Petry committed Apr 29, 2016
1 parent 8696fc9 commit 99bc095
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion apps/files_external/lib/storage/smb.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function getId() {
* @return string
*/
protected function buildPath($path) {
return Filesystem::normalizePath($this->root . '/' . $path);
return Filesystem::normalizePath($this->root . '/' . $path, true, false, true);
}

/**
Expand Down
21 changes: 8 additions & 13 deletions lib/private/Files/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -789,11 +789,12 @@ static public function hasUpdated($path, $time) {
* Fix common problems with a file path
*
* @param string $path
* @param bool $stripTrailingSlash
* @param bool $isAbsolutePath
* @param bool $stripTrailingSlash whether to strip the trailing slash
* @param bool $isAbsolutePath whether the given path is absolute
* @param bool $keepUnicode true to disable unicode normalization
* @return string
*/
public static function normalizePath($path, $stripTrailingSlash = true, $isAbsolutePath = false) {
public static function normalizePath($path, $stripTrailingSlash = true, $isAbsolutePath = false, $keepUnicode = false) {
/**
* FIXME: This is a workaround for existing classes and files which call
* this function with another type than a valid string. This
Expand All @@ -813,19 +814,13 @@ public static function normalizePath($path, $stripTrailingSlash = true, $isAbsol
}

//normalize unicode if possible
$path = \OC_Util::normalizeUnicode($path);
if (!$keepUnicode) {
$path = \OC_Util::normalizeUnicode($path);
}

//no windows style slashes
$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
if ($path[0] !== '/') {
$path = '/' . $path;
Expand All @@ -851,7 +846,7 @@ public static function normalizePath($path, $stripTrailingSlash = true, $isAbsol
$path = substr($path, 0, -2);
}

$normalizedPath = $windows_drive_letter . $path;
$normalizedPath = $path;
self::$normalizedPathCache[$cacheKey] = $normalizedPath;

return $normalizedPath;
Expand Down

0 comments on commit 99bc095

Please sign in to comment.