[Pkg-owncloud-commits] [owncloud] 118/215: Fix file name validation in New menu

David Prévot taffit at moszumanska.debian.org
Tue May 5 01:01:33 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit 69f88b38c942e2b33ba1cbac7a9f2895b3380434
Author: Vincent Petry <pvince81 at owncloud.com>
Date:   Mon Apr 27 16:31:18 2015 +0200

    Fix file name validation in New menu
---
 apps/files/js/file-upload.js          | 12 ++-----
 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 ce8127c..6b6acdb 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 49b7265..817654c 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();
+		});
+	});
 });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list