Skip to content
Permalink
Browse files

Ignore invalid paths in the JS file list (#25368)

  • Loading branch information...
PVince81 authored and DeepDiver1975 committed Jul 6, 2016
1 parent a2e0573 commit c92c234059f8b1dc7d53122985ec0d398895a2cf
Showing with 39 additions and 0 deletions.
  1. +14 −0 apps/files/js/filelist.js
  2. +25 −0 apps/files/tests/js/filelistSpec.js
@@ -1327,13 +1327,27 @@
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
* @param changeUrl true to also update the URL, false otherwise (default)
*/
_setCurrentDir: function(targetDir, changeUrl) {
targetDir = targetDir.replace(/\\/g, '/');
if (!this._isValidPath(targetDir)) {
targetDir = '/';
changeUrl = true;
}
var previousDir = this.getCurrentDirectory(),
baseDir = OC.basename(targetDir);

@@ -1323,6 +1323,31 @@ describe('OCA.Files.FileList tests', function() {
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);

0 comments on commit c92c234

Please sign in to comment.
You can’t perform that action at this time.