aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2015-07-13 17:25:27 +0200
committerMorris Jobke <hey@morrisjobke.de>2015-07-13 17:25:27 +0200
commite18d0e26f6b5fbef555acacb7d1ec7adbff1c50e (patch)
tree1aec97acc15c3d2e3067f86f753ce7d7d864f015
parente4ed99572756dec2634ca0d18b0b78e97bb613ef (diff)
parent1b7d42c5691ffa21246022690f7688dda534c2dc (diff)
downloadnextcloud-server-e18d0e26f6b5fbef555acacb7d1ec7adbff1c50e.tar.gz
nextcloud-server-e18d0e26f6b5fbef555acacb7d1ec7adbff1c50e.zip
Merge pull request #17599 from owncloud/fix-joinpaths-trailingslash
Fix OC.joinPaths with empty arguments
-rw-r--r--core/js/js.js18
-rw-r--r--core/js/tests/specs/coreSpec.js4
2 files changed, 18 insertions, 4 deletions
diff --git a/core/js/js.js b/core/js/js.js
index 1dfcb576c2a..ba456b54c6d 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -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++) {
diff --git a/core/js/tests/specs/coreSpec.js b/core/js/tests/specs/coreSpec.js
index 7a09f362ee5..3ebe55305f7 100644
--- a/core/js/tests/specs/coreSpec.js
+++ b/core/js/tests/specs/coreSpec.js
@@ -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/');
});