Skip to content

Commit 39b2963

Browse files
committed
fix(substr): fix and improve substring matching
1 parent 2962dad commit 39b2963

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/util/url.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,14 +425,14 @@ export function toFileSystemPath(path: string | undefined, keepFileProtocol?: bo
425425

426426
// Step 3: If it's a "file://" URL, then format it consistently
427427
// or convert it to a local filesystem path
428-
let isFileUrl = path.substring(0, 7).toLowerCase() === "file://";
428+
let isFileUrl = path.toLowerCase().startsWith("file://");
429429
if (isFileUrl) {
430430
// Strip-off the protocol, and the initial "/", if there is one
431-
path = path[7] === "/" ? path.substring(8) : path.substring(7);
431+
path = path.replace(/^file:\/\//, "").replace(/^\//, "");
432432

433433
// insert a colon (":") after the drive letter on Windows
434434
if (isWindows() && path[1] === "/") {
435-
path = path[0] + ":" + path.substring(1);
435+
path = `${path[0]}:${path.substring(1)}`;
436436
}
437437

438438
if (keepFileProtocol) {
@@ -453,7 +453,7 @@ export function toFileSystemPath(path: string | undefined, keepFileProtocol?: bo
453453
path = path.replace(forwardSlashPattern, "\\");
454454

455455
// Capitalize the drive letter
456-
if (path.substring(1, 2) === ":\\") {
456+
if (path.match(/^[a-z]:\\/i)) {
457457
path = path[0].toUpperCase() + path.substring(1);
458458
}
459459
}

0 commit comments

Comments
 (0)