Skip to content
Open
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
20 changes: 17 additions & 3 deletions src/components/Modal/SaveAs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{{ t('richdocuments', 'Cancel') }}
</NcButton>
<NcButton type="primary"
:disabled="isChecking"
:disabled="isChecking || !isValidName"
@click="close">
{{ isChecking ? t('richdocuments', 'Checking…') : t('richdocuments', 'Save') }}
</NcButton>
Expand Down Expand Up @@ -72,7 +72,7 @@ export default {
emits: ['close'],
data() {
return {
selectedPath: '',
selectedPath: null,
isChecking: false,
}
},
Expand All @@ -85,7 +85,7 @@ export default {
},
newFileName: {
get() {
if (this.selectedPath !== '') {
if (this.selectedPath !== null) {
return this.selectedPath
}
const filename = this.path
Expand All @@ -97,6 +97,20 @@ export default {
this.selectedPath = value
},
},
isValidName() {
const value = this.newFileName.trim()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also validate against https://github.com/nextcloud-libraries/nextcloud-files/blob/main/lib/utils/filename-validation.ts#L120 but fine to get this in as it fixes the original bug

if (value === '') {
return false
}
const base = value.split('/').pop()
const parts = base.split('.')
let valid = true
// filename is non-empty
valid &&= base !== ''
// filename has both a name part and an extension
valid &&= parts.length >= 2 && parts.at(-2).length > 0 && parts.at(-1).length > 0
return valid
},
},
mounted() {
const filename = this.path
Expand Down
6 changes: 5 additions & 1 deletion src/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,14 @@ const documentsMain = {
}

if (msgId === 'UI_SaveAs') {
let docPath = documentsMain.fileName
if (documentsMain.fullPath && documentsMain.fullPath !== '/') {
docPath = documentsMain.fullPath
}
spawnDialog(
SaveAs,
{
path: documentsMain.fileName,
path: docPath,
format: args.format,
},
(value) => value && PostMessages.sendWOPIPostMessage('loolframe', 'Action_SaveAs', { Filename: value, Notify: true }),
Expand Down
Loading