Skip to content

Commit aa4c459

Browse files
Use relative instead of startsWith to handle paths with the same prefix
1 parent f7c1f06 commit aa4c459

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

extensions/ql-vscode/src/pure/files.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { pathExists, stat, readdir } from "fs-extra";
2-
import { join, resolve } from "path";
2+
import { isAbsolute, join, relative, resolve } from "path";
33

44
/**
55
* Recursively finds all .ql files in this set of Uris.
@@ -71,7 +71,13 @@ export function pathsEqual(path1: string, path2: string): boolean {
7171
* Returns true if `parent` contains `child`, or if they are equal.
7272
*/
7373
export function containsPath(parent: string, child: string): boolean {
74-
return normalizePath(child).startsWith(normalizePath(parent));
74+
const relativePath = relative(parent, child);
75+
return (
76+
!relativePath.startsWith("..") &&
77+
// On windows, if the two paths are in different drives, then the
78+
// relative path will be an absolute path to the other drive.
79+
!(process.platform === "win32" && isAbsolute(relativePath))
80+
);
7581
}
7682

7783
export async function readDirFullPaths(path: string): Promise<string[]> {

0 commit comments

Comments
 (0)