*/
isProcessing:function() {
var count = 0;
-
+
jQuery.each(this._uploads,function(i, data) {
if (data.state() === 'pending') {
count++;
add: function(e, data) {
OC.Upload.log('add', e, data);
var that = $(this);
-
+
// we need to collect all data upload objects before starting the upload so we can check their existence
// and set individual conflict actions. unfortunately there is only one variable that we can use to identify
// the selection a data upload is part of, so we have to collect them in data.originalFiles
// turning singleFileUploads off is not an option because we want to gracefully handle server errors like
// already exists
-
+
// create a container where we can store the data objects
if ( ! data.originalFiles.selection ) {
// initialize selection and remember number of files to upload
};
}
var selection = data.originalFiles.selection;
-
+
// add uploads
if ( selection.uploads.length < selection.filesToUpload ) {
// remember upload
selection.uploads.push(data);
}
-
+
//examine file
var file = data.files[0];
try {
// FIXME: not so elegant... need to refactor that method to return a value
- Files.isFileNameValid(file.name);
+ Files.isFileNameValid(file.name, FileList.getCurrentDirectory());
}
catch (errorMessage) {
data.textStatus = 'invalidcharacters';
data.errorThrown = errorMessage;
}
-
+
if (file.type === '' && file.size === 4096) {
data.textStatus = 'dirorzero';
data.errorThrown = t('files', 'Unable to upload {filename} as it is a directory or has 0 bytes',
{filename: file.name}
);
}
-
+
// add size
selection.totalBytes += file.size;
-
+
// check PHP upload limit
if (selection.totalBytes > $('#upload_limit').val()) {
data.textStatus = 'sizeexceedlimit';
'size2': humanFileSize($('#free_space').val())
});
}
-
+
// end upload for whole selection on error
if (data.errorThrown) {
// trigger fileupload fail
// check existing files when all is collected
if ( selection.uploads.length >= selection.filesToUpload ) {
-
+
//remove our selection hack:
delete data.originalFiles.selection;
var callbacks = {
-
+
onNoConflicts: function (selection) {
$.each(selection.uploads, function(i, upload) {
upload.submit();
};
OC.Upload.checkExistingFiles(selection, callbacks);
-
+
}
return true; // continue adding files
});
fileupload.on('fileuploadstop', function(e, data) {
OC.Upload.log('progress handle fileuploadstop', e, data);
-
+
$('#uploadprogresswrapper input.stop').fadeOut();
$('#uploadprogressbar').fadeOut();
Files.updateStorageStatistics();
if ($(this).children('p').length === 0) {
return;
}
-
+
$('#new .error').tipsy('hide');
$('#new li').each(function(i,element) {
var text=$(this).children('p').text();
$(this).data('text',text);
$(this).children('p').remove();
-
+
// add input field
var form = $('<form></form>');
var input = $('<input type="text">');
throw t('files', 'URL cannot be empty');
} else if (type !== 'web' && !Files.isFileNameValid(filename)) {
// Files.isFileNameValid(filename) throws an exception itself
- } else if ($('#dir').val() === '/' && filename === 'Shared') {
+ } else if (FileList.getCurrentDirectory() === '/' && filename.toLowerCase() === 'shared') {
throw t('files', 'In the home folder \'Shared\' is a reserved filename');
} else if (FileList.inList(filename)) {
throw t('files', '{new_name} already exists', {new_name: filename});
len = input.val().length;
}
input.selectRange(0, len);
-
var checkInput = function () {
var filename = input.val();
if (filename !== oldname) {
- if (!Files.isFileNameValid(filename)) {
- // Files.isFileNameValid(filename) throws an exception itself
- } else if($('#dir').val() === '/' && filename === 'Shared') {
- throw t('files','In the home folder \'Shared\' is a reserved filename');
- } else if (FileList.inList(filename)) {
+ // Files.isFileNameValid(filename) throws an exception itself
+ Files.isFileNameValid(filename, FileList.getCurrentDirectory());
+ if (FileList.inList(filename)) {
throw t('files', '{new_name} already exists', {new_name: filename});
}
}
* Throws a string exception with an error message if
* the file name is not valid
*/
- isFileNameValid: function (name) {
+ isFileNameValid: function (name, root) {
var trimmedName = name.trim();
- if (trimmedName === '.' || trimmedName === '..') {
+ if (trimmedName === '.'
+ || trimmedName === '..'
+ || (root === '/' && trimmedName.toLowerCase() === 'shared'))
+ {
throw t('files', '"{name}" is an invalid file name.', {name: name});
} else if (trimmedName.length === 0) {
throw t('files', 'File name cannot be empty.');
expect(error).toEqual(false);
}
});
+ it('Validates correct file names do not create Shared folder in root', function() {
+ // create shared file in subfolder
+ var error = false;
+ try {
+ expect(Files.isFileNameValid('shared', '/foo')).toEqual(true);
+ expect(Files.isFileNameValid('Shared', '/foo')).toEqual(true);
+ }
+ catch (e) {
+ error = e;
+ }
+ expect(error).toEqual(false);
+
+ // create shared file in root
+ var threwException = false;
+ try {
+ Files.isFileNameValid('Shared', '/');
+ console.error('Invalid file name not detected');
+ }
+ catch (e) {
+ threwException = true;
+ }
+ expect(threwException).toEqual(true);
+
+ // create shared file in root
+ var threwException = false;
+ try {
+ Files.isFileNameValid('shared', '/');
+ console.error('Invalid file name not detected');
+ }
+ catch (e) {
+ threwException = true;
+ }
+ expect(threwException).toEqual(true);
+
+ });
it('Detects invalid file names', function() {
var fileNames = [
'',