diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-04-27 16:31:18 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-04-27 16:31:18 +0200 |
commit | 69f88b38c942e2b33ba1cbac7a9f2895b3380434 (patch) | |
tree | 9831592c81a3b7da443d5e7da897611e879d610e /apps/files | |
parent | eb0e9e56467db90d0a8e828edbef0261c186cf37 (diff) | |
download | nextcloud-server-69f88b38c942e2b33ba1cbac7a9f2895b3380434.tar.gz nextcloud-server-69f88b38c942e2b33ba1cbac7a9f2895b3380434.zip |
Fix file name validation in New menu
Diffstat (limited to 'apps/files')
-rw-r--r-- | apps/files/js/file-upload.js | 12 | ||||
-rw-r--r-- | apps/files/tests/js/fileUploadSpec.js | 59 |
2 files changed, 61 insertions, 10 deletions
diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index ce8127c9887..6b6acdb5e01 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -611,7 +611,7 @@ OC.Upload = { var lastPos; var checkInput = function () { var filename = input.val(); - if (Files.isFileNameValid(filename)) { + if (!Files.isFileNameValid(filename)) { // Files.isFileNameValid(filename) throws an exception itself } else if (FileList.inList(filename)) { throw t('files', '{new_name} already exists', {new_name: filename}); @@ -651,12 +651,6 @@ OC.Upload = { FileList.lastAction(); } var name = FileList.getUniqueName(newname); - if (newname !== name) { - FileList.checkName(name, newname, true); - var hidden = true; - } else { - var hidden = false; - } switch(type) { case 'file': $.post( @@ -667,7 +661,7 @@ OC.Upload = { }, function(result) { if (result.status === 'success') { - FileList.add(result.data, {hidden: hidden, animate: true, scrollTo: true}); + FileList.add(result.data, {animate: true, scrollTo: true}); } else { OC.dialogs.alert(result.data.message, t('core', 'Could not create file')); } @@ -683,7 +677,7 @@ OC.Upload = { }, function(result) { if (result.status === 'success') { - FileList.add(result.data, {hidden: hidden, animate: true, scrollTo: true}); + FileList.add(result.data, {animate: true, scrollTo: true}); } else { OC.dialogs.alert(result.data.message, t('core', 'Could not create folder')); } diff --git a/apps/files/tests/js/fileUploadSpec.js b/apps/files/tests/js/fileUploadSpec.js index 49b7265ced1..817654c4fa9 100644 --- a/apps/files/tests/js/fileUploadSpec.js +++ b/apps/files/tests/js/fileUploadSpec.js @@ -35,7 +35,14 @@ describe('OC.Upload tests', function() { $('#testArea').append( '<input type="file" id="file_upload_start" name="files[]" multiple="multiple">' + '<input type="hidden" id="upload_limit" name="upload_limit" value="10000000">' + // 10 MB - '<input type="hidden" id="free_space" name="free_space" value="50000000">' // 50 MB + '<input type="hidden" id="free_space" name="free_space" value="50000000">' + // 50 MB + // TODO: handlebars! + '<div id="new">' + + '<a>New</a>' + + '<ul>' + + '<li data-type="file" data-newname="New text file.txt"><p>Text file</p></li>' + + '</ul>' + + '</div>' ); $dummyUploader = $('#file_upload_start'); }); @@ -111,4 +118,54 @@ describe('OC.Upload tests', function() { ); }); }); + describe('New file', function() { + var $input; + var currentDirStub; + + beforeEach(function() { + OC.Upload.init(); + $('#new>a').click(); + $('#new li[data-type=file]').click(); + $input = $('#new input[type=text]'); + + currentDirStub = sinon.stub(FileList, 'getCurrentDirectory'); + currentDirStub.returns('testdir'); + }); + afterEach(function() { + currentDirStub.restore(); + }); + it('sets default text in field', function() { + expect($input.length).toEqual(1); + expect($input.val()).toEqual('New text file.txt'); + }); + it('creates file when enter is pressed', function() { + $input.val('somefile.txt'); + $input.trigger(new $.Event('keyup', {keyCode: 13})); + $input.parent('form').submit(); + expect(fakeServer.requests.length).toEqual(2); + + var request = fakeServer.requests[1]; + expect(request.method).toEqual('POST'); + expect(request.url).toEqual(OC.webroot + '/index.php/apps/files/ajax/newfile.php'); + var query = OC.parseQueryString(request.requestBody); + expect(query).toEqual({ + dir: 'testdir', + filename: 'somefile.txt' + }); + }); + it('prevents entering invalid file names', function() { + $input.val('..'); + $input.trigger(new $.Event('keyup', {keyCode: 13})); + $input.parent('form').submit(); + expect(fakeServer.requests.length).toEqual(1); + }); + it('prevents entering file names that already exist', function() { + var inListStub = sinon.stub(FileList, 'inList').returns(true); + $input.val('existing.txt'); + $input.trigger(new $.Event('keyup', {keyCode: 13})); + $input.parent('form').submit(); + expect(fakeServer.requests.length).toEqual(1); + inListStub.restore(); + }); + }); }); |