mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 20:59:10 +00:00
fix: Allow isolated "%"s when parsing file URLs (#7108)
This commit is contained in:
parent
fd83df7cdb
commit
cf603be24c
4 changed files with 14 additions and 4 deletions
|
@ -63,11 +63,13 @@
|
|||
});
|
||||
}
|
||||
|
||||
// Keep in sync with `fromFileUrl()` in `std/path/win32.ts`.
|
||||
function pathFromURLWin32(url) {
|
||||
let path = decodeURIComponent(
|
||||
url.pathname
|
||||
.replace(/^\/*([A-Za-z]:)(\/|$)/, "$1/")
|
||||
.replace(/\//g, "\\"),
|
||||
.replace(/\//g, "\\")
|
||||
.replace(/%(?![0-9A-Fa-f]{2})/g, "%25"),
|
||||
);
|
||||
if (url.hostname != "") {
|
||||
// Note: The `URL` implementation guarantees that the drive letter and
|
||||
|
@ -78,12 +80,15 @@
|
|||
return path;
|
||||
}
|
||||
|
||||
// Keep in sync with `fromFileUrl()` in `std/path/posix.ts`.
|
||||
function pathFromURLPosix(url) {
|
||||
if (url.hostname !== "") {
|
||||
throw new TypeError(`Host must be empty.`);
|
||||
}
|
||||
|
||||
return decodeURIComponent(url.pathname);
|
||||
return decodeURIComponent(
|
||||
url.pathname.replace(/%(?![0-9A-Fa-f]{2})/g, "%25"),
|
||||
);
|
||||
}
|
||||
|
||||
function pathFromURL(pathOrUrl) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue