Skip to content

Commit f3f73ba

Browse files
authored
Merge pull request #44407 from nextcloud/fix/files-copy-move-escaping
fix(files): Do not escape file names in the file picker
2 parents c35e237 + 2a8d9e0 commit f3f73ba

File tree

9 files changed

+50
-12
lines changed

9 files changed

+50
-12
lines changed

apps/files/src/actions/moveOrCopyAction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ const openFilePickerForAction = async (action: MoveCopyAction, dir = '/', nodes:
212212

213213
if (action === MoveCopyAction.COPY || action === MoveCopyAction.MOVE_OR_COPY) {
214214
buttons.push({
215-
label: target ? t('files', 'Copy to {target}', { target }) : t('files', 'Copy'),
215+
label: target ? t('files', 'Copy to {target}', { target }, undefined, { escape: false, sanitize: false }) : t('files', 'Copy'),
216216
type: 'primary',
217217
icon: CopyIconSvg,
218218
async callback(destination: Node[]) {
@@ -237,7 +237,7 @@ const openFilePickerForAction = async (action: MoveCopyAction, dir = '/', nodes:
237237

238238
if (action === MoveCopyAction.MOVE || action === MoveCopyAction.MOVE_OR_COPY) {
239239
buttons.push({
240-
label: target ? t('files', 'Move to {target}', { target }) : t('files', 'Move'),
240+
label: target ? t('files', 'Move to {target}', { target }, undefined, { escape: false, sanitize: false }) : t('files', 'Move'),
241241
type: action === MoveCopyAction.MOVE ? 'primary' : 'secondary',
242242
icon: FolderMoveSvg,
243243
async callback(destination: Node[]) {

cypress/e2e/files/FilesUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const copyFile = (fileName: string, dirName: string) => {
9090
cy.contains('button', 'Copy').should('be.visible').click()
9191
} else {
9292
// select folder
93-
cy.get(`[data-filename="${dirName}"]`).should('be.visible').click()
93+
cy.get(`[data-filename="${CSS.escape(dirName)}"]`).should('be.visible').click()
9494
// click copy
9595
cy.contains('button', `Copy to ${dirName}`).should('be.visible').click()
9696
}

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ describe('Files: Move or copy files', { testIsolation: true }, () => {
3535
cy.deleteUser(currentUser)
3636
})
3737

38+
3839
it('Can copy a file to new folder', () => {
3940
// Prepare initial state
4041
cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
@@ -136,4 +137,41 @@ describe('Files: Move or copy files', { testIsolation: true }, () => {
136137
getRowForFile('original.txt').should('be.visible')
137138
getRowForFile('original (copy 2).txt').should('be.visible')
138139
})
140+
141+
/** Test for https://github.com/nextcloud/server/issues/43329 */
142+
context.only('escaping file and folder names', () => {
143+
it('Can handle files with special characters', () => {
144+
cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
145+
.mkdir(currentUser, '/can\'t say')
146+
cy.login(currentUser)
147+
cy.visit('/apps/files')
148+
149+
copyFile('original.txt', 'can\'t say')
150+
151+
navigateToFolder('can\'t say')
152+
153+
cy.url().should('contain', 'dir=/can%27t%20say')
154+
getRowForFile('original.txt').should('be.visible')
155+
getRowForFile('can\'t say').should('not.exist')
156+
})
157+
158+
/**
159+
* If escape is set to false (required for test above) then "<a>foo" would result in "<a>foo</a>" if sanitizing is not disabled
160+
* We should disable it as vue already escapes the text when using v-text
161+
*/
162+
it('does not incorrectly sanitize file names', () => {
163+
cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
164+
.mkdir(currentUser, '/<a href="#">foo')
165+
cy.login(currentUser)
166+
cy.visit('/apps/files')
167+
168+
copyFile('original.txt', '<a href="#">foo')
169+
170+
navigateToFolder('<a href="#">foo')
171+
172+
cy.url().should('contain', 'dir=/%3Ca%20href%3D%22%23%22%3Efoo')
173+
getRowForFile('original.txt').should('be.visible')
174+
getRowForFile('<a href="#">foo').should('not.exist')
175+
})
176+
})
139177
})

dist/core-common.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core-common.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-init.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-init.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)