diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-12-21 13:10:03 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2016-10-24 21:45:00 +0200 |
commit | 25d9dce067dcc068ceb554033b3ed164b8645555 (patch) | |
tree | ffd364bd89514f5712517ff30d8029315d7a4847 /core/js/tests | |
parent | 59c5be1cc572793a8d50e87ab589e1cc4cf2ed12 (diff) | |
download | nextcloud-server-25d9dce067dcc068ceb554033b3ed164b8645555.tar.gz nextcloud-server-25d9dce067dcc068ceb554033b3ed164b8645555.zip |
JS utility function to compare paths
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'core/js/tests')
-rw-r--r-- | core/js/tests/specs/coreSpec.js | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/core/js/tests/specs/coreSpec.js b/core/js/tests/specs/coreSpec.js index 01a0e6acb6f..5d42f0881d4 100644 --- a/core/js/tests/specs/coreSpec.js +++ b/core/js/tests/specs/coreSpec.js @@ -188,6 +188,71 @@ describe('Core base tests', function() { expect(OC.joinPaths('/', '//', '/')).toEqual('/'); }); }); + describe('isSamePath', function() { + it('recognizes empty paths are equal', function() { + expect(OC.isSamePath('', '')).toEqual(true); + expect(OC.isSamePath('/', '')).toEqual(true); + expect(OC.isSamePath('//', '')).toEqual(true); + expect(OC.isSamePath('/', '/')).toEqual(true); + expect(OC.isSamePath('/', '//')).toEqual(true); + }); + it('recognizes path with single sections as equal regardless of extra slashes', function() { + expect(OC.isSamePath('abc', 'abc')).toEqual(true); + expect(OC.isSamePath('/abc', 'abc')).toEqual(true); + expect(OC.isSamePath('//abc', 'abc')).toEqual(true); + expect(OC.isSamePath('abc', '/abc')).toEqual(true); + expect(OC.isSamePath('abc/', 'abc')).toEqual(true); + expect(OC.isSamePath('abc/', 'abc/')).toEqual(true); + expect(OC.isSamePath('/abc/', 'abc/')).toEqual(true); + expect(OC.isSamePath('/abc/', '/abc/')).toEqual(true); + expect(OC.isSamePath('//abc/', '/abc/')).toEqual(true); + expect(OC.isSamePath('//abc//', '/abc/')).toEqual(true); + + expect(OC.isSamePath('abc', 'def')).toEqual(false); + expect(OC.isSamePath('/abc', 'def')).toEqual(false); + expect(OC.isSamePath('//abc', 'def')).toEqual(false); + expect(OC.isSamePath('abc', '/def')).toEqual(false); + expect(OC.isSamePath('abc/', 'def')).toEqual(false); + expect(OC.isSamePath('abc/', 'def/')).toEqual(false); + expect(OC.isSamePath('/abc/', 'def/')).toEqual(false); + expect(OC.isSamePath('/abc/', '/def/')).toEqual(false); + expect(OC.isSamePath('//abc/', '/def/')).toEqual(false); + expect(OC.isSamePath('//abc//', '/def/')).toEqual(false); + }); + it('recognizes path with multiple sections as equal regardless of extra slashes', function() { + expect(OC.isSamePath('abc/def', 'abc/def')).toEqual(true); + expect(OC.isSamePath('/abc/def', 'abc/def')).toEqual(true); + expect(OC.isSamePath('abc/def', '/abc/def')).toEqual(true); + expect(OC.isSamePath('abc/def/', '/abc/def/')).toEqual(true); + expect(OC.isSamePath('/abc/def/', '/abc/def/')).toEqual(true); + expect(OC.isSamePath('/abc/def/', 'abc/def/')).toEqual(true); + expect(OC.isSamePath('//abc/def/', 'abc/def/')).toEqual(true); + expect(OC.isSamePath('//abc/def//', 'abc/def/')).toEqual(true); + + expect(OC.isSamePath('abc/def', 'abc/ghi')).toEqual(false); + expect(OC.isSamePath('/abc/def', 'abc/ghi')).toEqual(false); + expect(OC.isSamePath('abc/def', '/abc/ghi')).toEqual(false); + expect(OC.isSamePath('abc/def/', '/abc/ghi/')).toEqual(false); + expect(OC.isSamePath('/abc/def/', '/abc/ghi/')).toEqual(false); + expect(OC.isSamePath('/abc/def/', 'abc/ghi/')).toEqual(false); + expect(OC.isSamePath('//abc/def/', 'abc/ghi/')).toEqual(false); + expect(OC.isSamePath('//abc/def//', 'abc/ghi/')).toEqual(false); + }); + it('recognizes path entries with dot', function() { + expect(OC.isSamePath('.', '')).toEqual(true); + expect(OC.isSamePath('.', '.')).toEqual(true); + expect(OC.isSamePath('.', '/')).toEqual(true); + expect(OC.isSamePath('/.', '/')).toEqual(true); + expect(OC.isSamePath('/./', '/')).toEqual(true); + expect(OC.isSamePath('/./', '/.')).toEqual(true); + expect(OC.isSamePath('/./', '/./')).toEqual(true); + expect(OC.isSamePath('/./', '/./')).toEqual(true); + + expect(OC.isSamePath('a/./b', 'a/b')).toEqual(true); + expect(OC.isSamePath('a/b/.', 'a/b')).toEqual(true); + expect(OC.isSamePath('./a/b', 'a/b')).toEqual(true); + }); + }); describe('filePath', function() { beforeEach(function() { OC.webroot = 'http://localhost'; |