Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/Service/AttachmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ public function uploadAttachment(int $documentId, string $newFileName, $newFileR
throw new NotPermittedException('No write permissions');
}
$saveDir = $this->getAttachmentDirectoryForFile($textFile, true);
// The filecache stores names in Unicode NFC, while uploads from macOS may use NFD
$normalizedFileName = \Normalizer::normalize($newFileName, \Normalizer::FORM_C);
if ($normalizedFileName !== false) {
$newFileName = $normalizedFileName;
}
$fileName = self::getUniqueFileName($saveDir, $newFileName);
$this->filenameValidator->validateFilename($fileName);
$savedFile = $saveDir->newFile($fileName, $newFileResource);
Expand Down
6 changes: 5 additions & 1 deletion src/services/AttachmentResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ export default class AttachmentResolver {
}

#findAttachment(fileName) {
return this.#attachmentList.find((a) => a.name === fileName)
// Attachment srcs may use NFD (e.g. uploads from macOS), the attachment list uses NFC
const normalizedName = fileName.normalize('NFC')
return this.#attachmentList.find(
(a) => a.name.normalize('NFC') === normalizedName,
)
}

/*
Expand Down
21 changes: 21 additions & 0 deletions src/tests/services/AttachmentResolver.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,25 @@ describe('Image resolver', () => {
'http://localhost:3000/remote.php/dav/files/user-uid/parentDir/path/to/some%20image.png',
)
})

it('matches attachment names regardless of Unicode normalization', async () => {
const nfcName = 'B\u00FCcher.pdf'
const nfdName = 'Bu\u0308cher.pdf'
vi.spyOn(axios, 'post').mockReturnValue({
data: [
{
fileId: 1237,
name: nfcName,
mimetype: 'application/pdf',
isImage: false,
},
],
})
const resolver = new AttachmentResolver({ session })
const attachment = await resolver.resolve(
`.attachments.${session.documentId}/${encodeURIComponent(nfdName)}`,
)
expect(attachment.isImage).toBe(false)
expect(attachment.name).toBe(nfcName)
})
})
Loading