Skip to content

Commit 8dd1246

Browse files
emberfiendelzody
authored andcommitted
fix(SaveAs): improve filename validation, fix cant-empty-field bug, prefill path where available
Signed-off-by: Andrew Backhouse <andrew.backhouse@nextcloud.com>
1 parent 066ebb8 commit 8dd1246

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

src/components/Modal/SaveAs.vue

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
{{ t('richdocuments', 'Cancel') }}
2020
</NcButton>
2121
<NcButton type="primary"
22+
:disabled="!isValidName"
2223
@click="close">
2324
{{ t('richdocuments', 'Save') }}
2425
</NcButton>
@@ -66,13 +67,13 @@ export default {
6667
emits: ['close'],
6768
data() {
6869
return {
69-
selectedPath: '',
70+
selectedPath: null,
7071
}
7172
},
7273
computed: {
7374
newFileName: {
7475
get() {
75-
if (this.selectedPath !== '') {
76+
if (this.selectedPath !== null) {
7677
return this.selectedPath
7778
}
7879
const filename = this.path
@@ -84,6 +85,20 @@ export default {
8485
this.selectedPath = value
8586
},
8687
},
88+
isValidName() {
89+
const value = this.newFileName.trim()
90+
if (value === '') {
91+
return false
92+
}
93+
const base = value.split('/').pop()
94+
const parts = base.split('.')
95+
let valid = true
96+
// filename is non-empty
97+
valid &&= base !== ''
98+
// filename has both a name part and an extension
99+
valid &&= parts.length >= 2 && parts.at(-2).length > 0 && parts.at(-1).length > 0
100+
return valid
101+
},
87102
},
88103
mounted() {
89104
// prepare filename for having a separate picker for the path (.split('/').pop())

src/document.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,14 @@ const documentsMain = {
470470
}
471471

472472
if (msgId === 'UI_SaveAs') {
473+
let docPath = documentsMain.fileName
474+
if (documentsMain.fullPath && documentsMain.fullPath !== '/') {
475+
docPath = documentsMain.fullPath
476+
}
473477
spawnDialog(
474478
SaveAs,
475479
{
476-
path: documentsMain.fileName,
480+
path: docPath,
477481
format: args.format,
478482
},
479483
(value) => value && PostMessages.sendWOPIPostMessage('loolframe', 'Action_SaveAs', { Filename: value, Notify: true }),

0 commit comments

Comments
 (0)