return OC.linkTo('files', 'index.php')+"?dir="+ encodeURIComponent(dir).replace(/%2F/g, '/');
},
+ _isValidPath: function(path) {
+ var sections = path.split('/');
+ for (var i = 0; i < sections.length; i++) {
+ if (sections[i] === '..') {
+ return false;
+ }
+ }
+ return true;
+ },
+
/**
* Sets the current directory name and updates the breadcrumb.
* @param targetDir directory to display
*/
_setCurrentDir: function(targetDir, changeUrl, fileId) {
targetDir = targetDir.replace(/\\/g, '/');
+ if (!this._isValidPath(targetDir)) {
+ targetDir = '/';
+ changeUrl = true;
+ }
var previousDir = this.getCurrentDirectory(),
baseDir = OC.basename(targetDir);
fileList.changeDirectory('/another\\subdir');
expect(fileList.getCurrentDirectory()).toEqual('/another/subdir');
});
+ it('switches to root dir when current directory is invalid', function() {
+ _.each([
+ '..',
+ '/..',
+ '../',
+ '/../',
+ '/../abc',
+ '/abc/..',
+ '/abc/../',
+ '/../abc/'
+ ], function(path) {
+ fileList.changeDirectory(path);
+ expect(fileList.getCurrentDirectory()).toEqual('/');
+ });
+ });
+ it('allows paths with dotdot at the beginning or end', function() {
+ _.each([
+ '..abc',
+ 'def..',
+ '...'
+ ], function(path) {
+ fileList.changeDirectory(path);
+ expect(fileList.getCurrentDirectory()).toEqual(path);
+ });
+ });
it('switches to root dir when current directory does not exist', function() {
fileList.changeDirectory('/unexist');
deferredList.reject(404);