diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-08-17 10:39:06 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-17 10:39:06 -0400 |
commit | 4535f79a4afb3bd58e46b9fbbb216cffe9d05129 (patch) | |
tree | e6cd40fe05214dfe04be4e22376a23a72fec21e1 /ext/node/ops/require.rs | |
parent | 23ff0e722e3c4b0827940853c53c5ee2ede5ec9f (diff) |
fix(npm): do not panic providing file url to require.resolve paths (#20182)
Closes #19922
Diffstat (limited to 'ext/node/ops/require.rs')
-rw-r--r-- | ext/node/ops/require.rs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/ext/node/ops/require.rs b/ext/node/ops/require.rs index f91970eef..3b77ff571 100644 --- a/ext/node/ops/require.rs +++ b/ext/node/ops/require.rs @@ -95,13 +95,17 @@ where { let fs = state.borrow::<FileSystemRc>(); // Guarantee that "from" is absolute. - let from = deno_core::resolve_path( - &from, - &(fs.cwd().map_err(AnyError::from)).context("Unable to get CWD")?, - ) - .unwrap() - .to_file_path() - .unwrap(); + let from = if from.starts_with("file:///") { + Url::parse(&from)?.to_file_path().unwrap() + } else { + deno_core::resolve_path( + &from, + &(fs.cwd().map_err(AnyError::from)).context("Unable to get CWD")?, + ) + .unwrap() + .to_file_path() + .unwrap() + }; ensure_read_permission::<P>(state, &from)?; |