Skip to content

Commit a289fdd

Browse files
committed
fix(files): Allow to copy or move file to folder with similar name
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent b29c0cc commit a289fdd

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

apps/files/src/actions/moveOrCopyAction.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ export const handleCopyMoveNodeTo = async (node: Node, destination: Folder, meth
8989
* Do not allow as it would copy foo within itself
9090
* - node: /foo/bar.txt, destination: /foo
9191
* Allow copy a file to the same directory
92+
* - node: "/foo/bar", destination: "/foo/bar 1"
93+
* Allow to move or copy but we need to check with trailing / otherwise it would report false positive
9294
*/
93-
if (destination.path.startsWith(node.path)) {
95+
if (`${destination.path}/`.startsWith(`${node.path}/`)) {
9496
throw new Error(t('files', 'You cannot move a file/folder onto itself or into a subfolder of itself'))
9597
}
9698

cypress/e2e/files/files_copy-move.cy.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,37 @@ describe('Files: Move or copy files', { testIsolation: true }, () => {
100100
getRowForFile('new-folder').should('not.exist')
101101
})
102102

103+
// This was a bug previously
104+
it('Can move a file to folder with similar name', () => {
105+
cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original')
106+
.mkdir(currentUser, '/original folder')
107+
cy.login(currentUser)
108+
cy.visit('/apps/files')
109+
110+
// intercept the copy so we can wait for it
111+
cy.intercept('MOVE', /\/remote.php\/dav\/files\//).as('moveFile')
112+
113+
getRowForFile('original').should('be.visible')
114+
triggerActionForFile('original', 'move-copy')
115+
116+
// select new folder
117+
cy.get('.file-picker [data-filename="original folder"]').should('be.visible').click()
118+
// click copy
119+
cy.get('.file-picker').contains('button', 'Move to original folder').should('be.visible').click()
120+
121+
cy.wait('@moveFile')
122+
// wait until visible again
123+
getRowForFile('original folder').should('be.visible')
124+
125+
// original should be moved -> not exist anymore
126+
getRowForFile('original').should('not.exist')
127+
getRowForFile('original folder').should('be.visible').find('[data-cy-files-list-row-name-link]').click()
128+
129+
cy.url().should('contain', 'dir=/original%20folder')
130+
getRowForFile('original').should('be.visible')
131+
getRowForFile('original folder').should('not.exist')
132+
})
133+
103134
it('Can move a file to its parent folder', () => {
104135
cy.mkdir(currentUser, '/new-folder')
105136
cy.uploadContent(currentUser, new Blob(), 'text/plain', '/new-folder/original.txt')

0 commit comments

Comments
 (0)