Files
Jonas 1d769fcfb6 fix(files): normalize Unicode in node paths
Filesystem::normalizePath() converts paths to Unicode NFC, so the
filecache and storage always use NFC names. The Node API uses
PathHelper::normalizePath() instead, which didn't normalize Unicode.
Nodes returned by Folder::newFile(), Folder::newFolder(), Node::copy()
and Node::move() therefore kept the name exactly as passed in.

Files uploaded from macOS in Chrome or Firefox have NFD names. Apps that
return $node->getName() after creating such a file sent back an NFD name
for a file that is stored as NFC. Other clients then couldn't match the
name against file listings, which broke attachments in Collectives and
Text.

Normalize to NFC in PathHelper::normalizePath(), like
Filesystem::normalizePath() does. Hooks and events emitted by the Node
API now get NFC paths as well.

Refs: nextcloud/collectives#2327
Refs: nextcloud/text#7873

Signed-off-by: Jonas <jonas@freesources.org>
Assisted-by: ClaudeCode:claude-opus-5-5
2026-10-15 16:39:50 +00:00

34 lines
798 B
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Files\Utils;
use OC\Files\Utils\PathHelper;
use Test\TestCase;
class PathHelperTest extends TestCase {
public static function normalizePathData(): array {
return [
['/', ''],
['/', '/'],
['/foo/bar', 'foo//bar/'],
['/foo/bar', '\\foo\\bar'],
['/foobar', "/foo\0bar"],
["/B\u{00FC}cher", "/Bu\u{0308}cher"],
["/B\u{00FC}cher", "/B\u{00FC}cher"],
["/a\xFFb", "/a\xFFb"],
];
}
#[\PHPUnit\Framework\Attributes\DataProvider('normalizePathData')]
public function testNormalizePath(string $expected, string $path): void {
$this->assertSame($expected, PathHelper::normalizePath($path));
}
}