Commit e18d0e26 authored by Morris Jobke's avatar Morris Jobke
Browse files

Merge pull request #17599 from owncloud/fix-joinpaths-trailingslash

Fix OC.joinPaths with empty arguments
parents e4ed9957 1b7d42c5
......@@ -385,13 +385,23 @@ var OC={
return '';
}
var path = '';
var lastArg = arguments[arguments.length - 1];
var leadingSlash = arguments[0].charAt(0) === '/';
// convert to array
var args = Array.prototype.slice.call(arguments);
// discard empty arguments
args = _.filter(args, function(arg) {
return arg.length > 0;
});
if (args.length < 1) {
return '';
}
var lastArg = args[args.length - 1];
var leadingSlash = args[0].charAt(0) === '/';
var trailingSlash = lastArg.charAt(lastArg.length - 1) === '/';
var sections = [];
var i;
for (i = 0; i < arguments.length; i++) {
sections = sections.concat(arguments[i].split('/'));
for (i = 0; i < args.length; i++) {
sections = sections.concat(args[i].split('/'));
}
var first = !leadingSlash;
for (i = 0; i < sections.length; i++) {
......
......@@ -147,11 +147,15 @@ describe('Core base tests', function() {
});
it('keeps leading slashes', function() {
expect(OC.joinPaths('/abc')).toEqual('/abc');
expect(OC.joinPaths('/abc', '')).toEqual('/abc');
expect(OC.joinPaths('', '/abc')).toEqual('/abc');
expect(OC.joinPaths('/abc', 'def')).toEqual('/abc/def');
expect(OC.joinPaths('/abc', 'def', 'ghi')).toEqual('/abc/def/ghi');
});
it('keeps trailing slashes', function() {
expect(OC.joinPaths('', 'abc/')).toEqual('abc/');
expect(OC.joinPaths('abc/')).toEqual('abc/');
expect(OC.joinPaths('abc/', '')).toEqual('abc/');
expect(OC.joinPaths('abc', 'def/')).toEqual('abc/def/');
expect(OC.joinPaths('abc', 'def', 'ghi/')).toEqual('abc/def/ghi/');
});
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment