From 4535f79a4afb3bd58e46b9fbbb216cffe9d05129 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 17 Aug 2023 10:39:06 -0400 Subject: fix(npm): do not panic providing file url to require.resolve paths (#20182) Closes #19922 --- ext/node/ops/require.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'ext/node/ops') 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::(); // 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::

(state, &from)?; -- cgit v1.2.3