Skip to content

Commit fc9e12b

Browse files
authored
Merge pull request #5718 from nextcloud/backport/5689/stable30
[stable30] fix(SaveAs): improve filename validation, fix cant-empty-field bug, prefill path where available
2 parents 066ebb8 + 2347aaf commit fc9e12b

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

cypress/e2e/direct.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ describe('Direct editing (legacy)', function() {
183183
.should('be.visible')
184184
cy.get('.saveas-dialog input[type=text]')
185185
.should('be.visible')
186-
.should('have.value', 'document.rtf')
186+
.should('have.value', '/document.rtf')
187187

188188
cy.get('.saveas-dialog button.button-vue--vue-primary').click()
189189

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)