mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Fix indexing error in guessDirectorySymlink (#46105)
* Fix indexing error in guessDirectorySymlink * Add test
This commit is contained in:
@@ -6381,9 +6381,12 @@ namespace ts {
|
||||
const aParts = getPathComponents(getNormalizedAbsolutePath(a, cwd));
|
||||
const bParts = getPathComponents(getNormalizedAbsolutePath(b, cwd));
|
||||
let isDirectory = false;
|
||||
while (!isNodeModulesOrScopedPackageDirectory(aParts[aParts.length - 2], getCanonicalFileName) &&
|
||||
while (
|
||||
aParts.length >= 2 && bParts.length >= 2 &&
|
||||
!isNodeModulesOrScopedPackageDirectory(aParts[aParts.length - 2], getCanonicalFileName) &&
|
||||
!isNodeModulesOrScopedPackageDirectory(bParts[bParts.length - 2], getCanonicalFileName) &&
|
||||
getCanonicalFileName(aParts[aParts.length - 1]) === getCanonicalFileName(bParts[bParts.length - 1])) {
|
||||
getCanonicalFileName(aParts[aParts.length - 1]) === getCanonicalFileName(bParts[bParts.length - 1])
|
||||
) {
|
||||
aParts.pop();
|
||||
bParts.pop();
|
||||
isDirectory = true;
|
||||
@@ -6393,8 +6396,8 @@ namespace ts {
|
||||
|
||||
// KLUDGE: Don't assume one 'node_modules' links to another. More likely a single directory inside the node_modules is the symlink.
|
||||
// ALso, don't assume that an `@foo` directory is linked. More likely the contents of that are linked.
|
||||
function isNodeModulesOrScopedPackageDirectory(s: string, getCanonicalFileName: GetCanonicalFileName): boolean {
|
||||
return getCanonicalFileName(s) === "node_modules" || startsWith(s, "@");
|
||||
function isNodeModulesOrScopedPackageDirectory(s: string | undefined, getCanonicalFileName: GetCanonicalFileName): boolean {
|
||||
return s !== undefined && (getCanonicalFileName(s) === "node_modules" || startsWith(s, "@"));
|
||||
}
|
||||
|
||||
function stripLeadingDirectorySeparator(s: string): string | undefined {
|
||||
|
||||
@@ -57,6 +57,11 @@ namespace ts.projectSystem {
|
||||
{ real: "/packages/dep/", realPath: "/packages/dep/" as Path }
|
||||
);
|
||||
});
|
||||
|
||||
it("works for paths close to the root", () => {
|
||||
const cache = createSymlinkCache("/", createGetCanonicalFileName(/*useCaseSensitiveFileNames*/ false));
|
||||
cache.setSymlinkedDirectoryFromSymlinkedFile("/foo", "/one/two/foo"); // Used to crash, #44953
|
||||
});
|
||||
});
|
||||
|
||||
function setup() {
|
||||
|
||||
Reference in New Issue
Block a user