Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/compiler/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,10 @@ function simpleNormalizePath(path: string): string | undefined {
}
// Some paths only require cleanup of `/./` or leading `./`
let simplified = path.replace(/\/\.\//g, "/");
if (simplified.startsWith("./")) {
// Only strip a leading `./` when it is an actual `.` segment, not the
// start of a `.//` sequence where the second slash is a redundant
// separator (stripping there would turn a relative path into a rooted one).
if (simplified.startsWith("./") && simplified.charCodeAt(2) !== CharacterCodes.slash) {
simplified = simplified.slice(2);
}
if (simplified !== path) {
Expand Down
4 changes: 4 additions & 0 deletions src/testRunner/unittests/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ describe("unittests:: core paths", () => {
assert.strictEqual(ts.getNormalizedAbsolutePath(".", ""), "");
assert.strictEqual(ts.getNormalizedAbsolutePath("./", ""), "");
assert.strictEqual(ts.getNormalizedAbsolutePath("./a", ""), "a");
// A `./` followed by a redundant separator must stay relative, not become rooted.
assert.strictEqual(ts.getNormalizedAbsolutePath(".//a", ""), "a");
assert.strictEqual(ts.getNormalizedAbsolutePath(".//a/b", ""), "a/b");
assert.strictEqual(ts.getNormalizedAbsolutePath("././/a", ""), "a");
// Strangely, these do not normalize to the empty string.
assert.strictEqual(ts.getNormalizedAbsolutePath("..", ""), "..");
assert.strictEqual(ts.getNormalizedAbsolutePath("../", ""), "..");
Expand Down