diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-01-19 20:19:59 +0100 |
---|---|---|
committer | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-01-20 15:41:53 +0100 |
commit | a289fdd2d757c85888efaaa2bcfe06733976fd88 (patch) | |
tree | 2bec566bc76ac6f0810a21028395928d152ded3f | |
parent | b29c0cca24188fdd01679045cfdd18c91fad9a15 (diff) | |
download | nextcloud-server-a289fdd2d757c85888efaaa2bcfe06733976fd88.tar.gz nextcloud-server-a289fdd2d757c85888efaaa2bcfe06733976fd88.zip |
fix(files): Allow to copy or move file to folder with similar name
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
-rw-r--r-- | apps/files/src/actions/moveOrCopyAction.ts | 4 | ||||
-rw-r--r-- | cypress/e2e/files/files_copy-move.cy.ts | 31 |
2 files changed, 34 insertions, 1 deletions
diff --git a/apps/files/src/actions/moveOrCopyAction.ts b/apps/files/src/actions/moveOrCopyAction.ts index 42ae82bb261..a4e70caf37d 100644 --- a/apps/files/src/actions/moveOrCopyAction.ts +++ b/apps/files/src/actions/moveOrCopyAction.ts @@ -89,8 +89,10 @@ export const handleCopyMoveNodeTo = async (node: Node, destination: Folder, meth * Do not allow as it would copy foo within itself * - node: /foo/bar.txt, destination: /foo * Allow copy a file to the same directory + * - node: "/foo/bar", destination: "/foo/bar 1" + * Allow to move or copy but we need to check with trailing / otherwise it would report false positive */ - if (destination.path.startsWith(node.path)) { + if (`${destination.path}/`.startsWith(`${node.path}/`)) { throw new Error(t('files', 'You cannot move a file/folder onto itself or into a subfolder of itself')) } diff --git a/cypress/e2e/files/files_copy-move.cy.ts b/cypress/e2e/files/files_copy-move.cy.ts index 49be392bc93..c301ba3bff7 100644 --- a/cypress/e2e/files/files_copy-move.cy.ts +++ b/cypress/e2e/files/files_copy-move.cy.ts @@ -100,6 +100,37 @@ describe('Files: Move or copy files', { testIsolation: true }, () => { getRowForFile('new-folder').should('not.exist') }) + // This was a bug previously + it('Can move a file to folder with similar name', () => { + cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original') + .mkdir(currentUser, '/original folder') + cy.login(currentUser) + cy.visit('/apps/files') + + // intercept the copy so we can wait for it + cy.intercept('MOVE', /\/remote.php\/dav\/files\//).as('moveFile') + + getRowForFile('original').should('be.visible') + triggerActionForFile('original', 'move-copy') + + // select new folder + cy.get('.file-picker [data-filename="original folder"]').should('be.visible').click() + // click copy + cy.get('.file-picker').contains('button', 'Move to original folder').should('be.visible').click() + + cy.wait('@moveFile') + // wait until visible again + getRowForFile('original folder').should('be.visible') + + // original should be moved -> not exist anymore + getRowForFile('original').should('not.exist') + getRowForFile('original folder').should('be.visible').find('[data-cy-files-list-row-name-link]').click() + + cy.url().should('contain', 'dir=/original%20folder') + getRowForFile('original').should('be.visible') + getRowForFile('original folder').should('not.exist') + }) + it('Can move a file to its parent folder', () => { cy.mkdir(currentUser, '/new-folder') cy.uploadContent(currentUser, new Blob(), 'text/plain', '/new-folder/original.txt') |