From 25d9dce067dcc068ceb554033b3ed164b8645555 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 21 Dec 2015 13:10:03 +0100 Subject: JS utility function to compare paths Signed-off-by: Roeland Jago Douma --- core/js/js.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'core/js/js.js') diff --git a/core/js/js.js b/core/js/js.js index 16da273c8e1..0db9967094b 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -422,6 +422,28 @@ var OC={ return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, ''); }, + /** + * Returns whether the given paths are the same, without + * leading, trailing or doubled slashes and also removing + * the dot sections. + * + * @param {String} path1 first path + * @param {String} path2 second path + * @return {bool} true if the paths are the same + * + * @since 9.0 + */ + isSamePath: function(path1, path2) { + var filterDot = function(p) { + return p !== '.'; + }; + var pathSections1 = _.filter((path1 || '').split('/'), filterDot); + var pathSections2 = _.filter((path2 || '').split('/'), filterDot); + path1 = OC.joinPaths.apply(OC, pathSections1); + path2 = OC.joinPaths.apply(OC, pathSections2); + return path1 === path2; + }, + /** * Join path sections * -- cgit v1.2.3