Improve directoryContains() (#2335)

This commit is contained in:
qqobb 2022-02-10 09:17:46 +01:00 committed by GitHub
parent f509e9063a
commit 47799adb3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1094,8 +1094,12 @@ Zotero.File = new function(){
if (typeof dir != 'string') throw new Error("dir must be a string");
if (typeof file != 'string') throw new Error("file must be a string");
dir = OS.Path.normalize(dir);
file = OS.Path.normalize(file);
dir = OS.Path.normalize(dir).replace(/\\/g, "/");
file = OS.Path.normalize(file).replace(/\\/g, "/");
// Normalize D:\ vs. D:\foo
if (dir != file && !dir.endsWith('/')) {
dir += '/';
}
return file.startsWith(dir);
};