fix: decode path properly on win32
@@ -82,19 +82,21 @@ export function immutableDefine(
}
function pathFromURLWin32(url: URL): string {
- if (url.hostname !== "") {
+ const hostname = url.hostname;
+ const pathname = decodeURIComponent(url.pathname.replace(/\//g, "\\"));
+
+ if (hostname !== "") {
//TODO(actual-size) Node adds a punycode decoding step, we should consider adding this
- return `\\\\${url.hostname}${url.pathname}`;
+ return `\\\\${hostname}${pathname}`;
}
- const validPath = /^\/(?<driveLetter>[A-Za-z]):\//;
- const matches = validPath.exec(url.pathname);
+ const validPath = /^\\(?<driveLetter>[A-Za-z]):\\/;
+ const matches = validPath.exec(pathname);
if (!matches?.groups?.driveLetter) {
throw new TypeError("A URL with the file schema must be absolute.");
}
- const pathname = url.pathname.replace(/\//g, "\\");
// we don't want a leading slash on an absolute path in Windows
return pathname.slice(1);
}
