|
@@ -115,17 +115,19 @@
|
|
});
|
|
});
|
|
|
|
|
|
file.item.find('.rename').on('click', function() {
|
|
file.item.find('.rename').on('click', function() {
|
|
- var to = prompt('Please enter the new name for "' + file.name + '":', file.name);
|
|
|
|
|
|
+ var to = prompt('Please enter the new name for "' + file.name + '":', decodeURIComponent(file.name));
|
|
|
|
|
|
- if (!to.match(/^[a-z0-9_\-\.]+$/i)) {
|
|
|
|
- _message('Bad file name.');
|
|
|
|
- to = false;
|
|
|
|
|
|
+ if (!to) {
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
|
|
- if (to) {
|
|
|
|
- WebDAV.rename(file, file.path + to);
|
|
|
|
|
|
+ if (!_validateFileName(to)) {
|
|
|
|
+ _message('Bad file name.');
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ WebDAV.rename(file, file.path + to);
|
|
|
|
+
|
|
return false;
|
|
return false;
|
|
});
|
|
});
|
|
|
|
|
|
@@ -215,6 +217,24 @@
|
|
|
|
|
|
return file;
|
|
return file;
|
|
},
|
|
},
|
|
|
|
+ _validateFileName = function(filename) {
|
|
|
|
+ if (!filename) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ else if (!filename.match(/^[\w \-\.]+$/)) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ else if (filename.match(/^\.\.?$/)) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+ },
|
|
|
|
+ _makeSafePath = function(path) {
|
|
|
|
+ return decodeURIComponent(path).replace(/[^\w\/\-\.]/g, function(char) {
|
|
|
|
+ return encodeURIComponent(char);
|
|
|
|
+ });
|
|
|
|
+ },
|
|
_getFileName = function(path) {
|
|
_getFileName = function(path) {
|
|
path = path.replace(/\/$/, '');
|
|
path = path.replace(/\/$/, '');
|
|
|
|
|
|
@@ -289,8 +309,8 @@
|
|
console.log(message);
|
|
console.log(message);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- _refreshDisplay = function() {
|
|
|
|
- return WebDAV.list(_path);
|
|
|
|
|
|
+ _refreshDisplay = function(forceRefresh) {
|
|
|
|
+ return WebDAV.list(_path, forceRefresh);
|
|
},
|
|
},
|
|
_renderFiles = function() {
|
|
_renderFiles = function() {
|
|
_sortFiles();
|
|
_sortFiles();
|
|
@@ -453,13 +473,8 @@
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
- if (!name.match(/^[\w \-\.]+$/)) {
|
|
|
|
- alert('Name contains non-standard characters, aborting.');
|
|
|
|
-
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- else if (name.match(/^\.\.?$/)) {
|
|
|
|
- alert('Cannot use a reserved name for your directory.');
|
|
|
|
|
|
+ if (!_validateFileName(name)) {
|
|
|
|
+ alert('Name contains unsupported characters, aborting.');
|
|
|
|
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
@@ -477,9 +492,7 @@
|
|
|
|
|
|
file = {
|
|
file = {
|
|
directory: true,
|
|
directory: true,
|
|
- name: name.replace(/[^\w\/\-\.]/g, function(char) {
|
|
|
|
- return encodeURIComponent(char);
|
|
|
|
- }),
|
|
|
|
|
|
+ name: _makeSafePath(name),
|
|
title: name,
|
|
title: name,
|
|
path: _path,
|
|
path: _path,
|
|
modified: Date.now(),
|
|
modified: Date.now(),
|
|
@@ -705,9 +718,7 @@
|
|
file.request = _request('DELETE', file.path + file.name);
|
|
file.request = _request('DELETE', file.path + file.name);
|
|
|
|
|
|
file.request.addEventListener('load', function(event) {
|
|
file.request.addEventListener('load', function(event) {
|
|
- delete _files[file.index];
|
|
|
|
- _cache[_path] = _files;
|
|
|
|
- _refreshDisplay();
|
|
|
|
|
|
+ _refreshDisplay(true);
|
|
}, false);
|
|
}, false);
|
|
|
|
|
|
file.request.addEventListener('error', function(event) {
|
|
file.request.addEventListener('error', function(event) {
|
|
@@ -747,11 +758,11 @@
|
|
move: function(from, to) {
|
|
move: function(from, to) {
|
|
// TODO
|
|
// TODO
|
|
from.request = _request('MOVE', from.path + from.name, {
|
|
from.request = _request('MOVE', from.path + from.name, {
|
|
- Destination: window.location.protocol + '//' + window.location.host + to
|
|
|
|
|
|
+ Destination: window.location.protocol + '//' + window.location.host + _makeSafePath(to)
|
|
});
|
|
});
|
|
|
|
|
|
from.request.addEventListener('load', function(event) {
|
|
from.request.addEventListener('load', function(event) {
|
|
- _refreshDisplay();
|
|
|
|
|
|
+ _refreshDisplay(true);
|
|
}, false);
|
|
}, false);
|
|
|
|
|
|
from.request.addEventListener('error', function(event) {
|
|
from.request.addEventListener('error', function(event) {
|