Skip to content

Commit 45eb819

Browse files
committed
Fix handling of invalid names
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
1 parent 298dadf commit 45eb819

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/Service/ZipService.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,14 @@ public function __construct(IRootFolder $rootFolder, NotificationService $notifi
6060
$this->jobList = $jobList;
6161
}
6262

63-
public function createZipJob(array $fileIds, $target): void {
63+
public function createZipJob(array $fileIds, string $target): void {
6464
$user = $this->userSession->getUser();
6565
if ($user === null) {
6666
throw new Exception('No user session available');
6767
}
68+
if (strlen($target) === 0) {
69+
throw new Exception('The target is invalid');
70+
}
6871
$this->jobList->add(ZipJob::class, [
6972
'uid' => $user->getUID(),
7073
'fileIds' => $fileIds,

src/main.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@ import { showError, showSuccess } from '@nextcloud/dialogs'
2222
t('files_zip', 'Select a name for the zip archive'),
2323
n('files_zip', 'Compress {files} file', 'Compress {files} files', selectedFiles.length, { files: selectedFiles.length }),
2424
(result, target) => {
25-
if (result) {
26-
this.compressFiles(selectedFiles, fileList.getCurrentDirectory() + '/' + target)
25+
if (!result) {
26+
return
2727
}
28+
if (target.length === 0) {
29+
showError(t('files_zip', 'The name selected is invalid.'))
30+
return
31+
}
32+
this.compressFiles(selectedFiles, fileList.getCurrentDirectory() + '/' + target)
2833
}, true, t('files_zip', 'File name')
2934
).then(this.enhancePrompt.bind(this, suggestedFilename))
3035
},

0 commit comments

Comments
 (0)