Skip to content

Commit 5cc78cb

Browse files
committed
fix: handle Windows file:// URL paths correctly
On Windows, URL.pathname returns paths like /D:/path which need the leading slash removed to become valid Windows paths like D:/path
1 parent ae1455c commit 5cc78cb

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/no-dead-link.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,14 @@ async function isAliveLocalFile(filePath: string): Promise<AliveFunctionReturn>
258258
let pathToCheck = filePath;
259259
if (filePath.startsWith("file://")) {
260260
const url = URL.parse(filePath);
261-
pathToCheck = url ? url.pathname : filePath;
261+
if (url && url.pathname) {
262+
// On Windows, pathname starts with / for drive letters (e.g., /C:/path)
263+
// We need to remove the leading slash for Windows paths
264+
pathToCheck =
265+
process.platform === "win32" && url.pathname.match(/^\/[A-Za-z]:/)
266+
? url.pathname.slice(1)
267+
: url.pathname;
268+
}
262269
}
263270
await fs.access(pathToCheck.replace(/[?#].*?$/, ""));
264271
return {

0 commit comments

Comments
 (0)