From a455af2b1696ffac548a48ce0dfe6b6ac2876673 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Wed, 26 Jul 2017 11:24:54 +0545 Subject: [PATCH] Do not allow slash in filename when renaming --- apps/files/js/files.js | 2 ++ apps/files/tests/js/filesSpec.js | 4 ++++ tests/ui/features/renameFiles.feature | 20 +++++++++++++++++--- tests/ui/features/renameFolders.feature | 24 ++++++++++++++++++------ 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 3a376177038e..e0a14bcf4935 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -101,6 +101,8 @@ throw t('files', '"{name}" is an invalid file name.', {name: name}); } else if (trimmedName.length === 0) { throw t('files', 'File name cannot be empty.'); + } else if (trimmedName.indexOf("/") >= 0) { + throw t('files', 'File name cannot contain "/".'); } else if (OC.fileIsBlacklisted(trimmedName)) { throw t('files', '"{name}" has a forbidden file type/extension.', {name: name}); } diff --git a/apps/files/tests/js/filesSpec.js b/apps/files/tests/js/filesSpec.js index c12873fdcbaa..86933deeb1a2 100644 --- a/apps/files/tests/js/filesSpec.js +++ b/apps/files/tests/js/filesSpec.js @@ -59,6 +59,10 @@ describe('OCA.Files.Files tests', function() { '.. ', '. ', ' .', + '/', + 'folder/', + '/file', + 'folder/file', 'foo.part', 'bar.filepart' ]; diff --git a/tests/ui/features/renameFiles.feature b/tests/ui/features/renameFiles.feature index 10ff1e69de09..84ea36d45ddb 100644 --- a/tests/ui/features/renameFiles.feature +++ b/tests/ui/features/renameFiles.feature @@ -36,7 +36,6 @@ Feature: renameFiles Scenario: Rename a file using forbidden characters When I rename the file "data.zip" to one of these names - |lorem/txt | |.htaccess | |lorem\txt | |\\.txt | @@ -44,9 +43,24 @@ Feature: renameFiles |Could not rename "data.zip"| |Could not rename "data.zip"| |Could not rename "data.zip"| - |Could not rename "data.zip"| And the file "data.zip" should be listed Scenario: Rename a file putting a name of a file which already exists When I rename the file "data.zip" to "lorem.txt" - Then near the file "data.zip" a tooltip with the text 'lorem.txt already exists' should be displayed \ No newline at end of file + Then near the file "data.zip" a tooltip with the text 'lorem.txt already exists' should be displayed + + Scenario: Rename a file using forward slash + When I rename the file "data.zip" to "lorem/txt" + Then near the file "data.zip" a tooltip with the text 'File name cannot contain "/".' should be displayed + + Scenario: Rename a file to .. + When I rename the file "data.zip" to ".." + Then near the file "data.zip" a tooltip with the text '".." is an invalid file name.' should be displayed + + Scenario: Rename a file to . + When I rename the file "data.zip" to "." + Then near the file "data.zip" a tooltip with the text '"." is an invalid file name.' should be displayed + + Scenario: Rename a file to .part + When I rename the file "data.zip" to "data.part" + Then near the file "data.zip" a tooltip with the text '"data.part" has a forbidden file type/extension.' should be displayed diff --git a/tests/ui/features/renameFolders.feature b/tests/ui/features/renameFolders.feature index 3f5a2df0696c..4a6f1c0fb762 100644 --- a/tests/ui/features/renameFolders.feature +++ b/tests/ui/features/renameFolders.feature @@ -35,19 +35,31 @@ Feature: renameFolders Scenario: Rename a folder using forbidden characters When I rename the folder "simple-folder" to one of these names - |simple/folder | |.htaccess | |simple\folder | - |\\simple/folder | - |../simple-folder| + |\\simple-folder | Then notifications should be displayed with the text |Could not rename "simple-folder"| |Could not rename "simple-folder"| |Could not rename "simple-folder"| - |Could not rename "simple-folder"| - |Could not rename "simple-folder"| And the folder "simple-folder" should be listed Scenario: Rename a folder putting a name of a file which already exists When I rename the folder "simple-folder" to "lorem.txt" - Then near the folder "simple-folder" a tooltip with the text 'lorem.txt already exists' should be displayed \ No newline at end of file + Then near the folder "simple-folder" a tooltip with the text 'lorem.txt already exists' should be displayed + + Scenario: Rename a folder using forward slash + When I rename the folder "simple-folder" to "simple/folder" + Then near the folder "simple-folder" a tooltip with the text 'File name cannot contain "/".' should be displayed + + Scenario: Rename a folder to .. + When I rename the folder "simple-folder" to ".." + Then near the folder "simple-folder" a tooltip with the text '".." is an invalid file name.' should be displayed + + Scenario: Rename a folder to . + When I rename the folder "simple-folder" to "." + Then near the folder "simple-folder" a tooltip with the text '"." is an invalid file name.' should be displayed + + Scenario: Rename a folder to .part + When I rename the folder "simple-folder" to "simple.part" + Then near the folder "simple-folder" a tooltip with the text '"simple.part" has a forbidden file type/extension.' should be displayed