diff --git a/cli/tests/integration/npm_tests.rs b/cli/tests/integration/npm_tests.rs index 49095b6dfd..ba9e1bdde4 100644 --- a/cli/tests/integration/npm_tests.rs +++ b/cli/tests/integration/npm_tests.rs @@ -689,6 +689,13 @@ itest!(deno_run_bin_esm { http_server: true, }); +itest!(deno_run_bin_special_chars { + args: "run -A --quiet npm:@denotest/special-chars-in-bin-name/\\foo\" this is a test", + output: "npm/deno_run_special_chars_in_bin_name.out", + envs: env_vars_for_npm_tests(), + http_server: true, +}); + itest!(deno_run_bin_no_ext { args: "run -A --quiet npm:@denotest/bin/cli-no-ext this is a test", output: "npm/deno_run_no_ext.out", diff --git a/cli/tests/testdata/npm/deno_run_special_chars_in_bin_name.out b/cli/tests/testdata/npm/deno_run_special_chars_in_bin_name.out new file mode 100644 index 0000000000..ffe7cbd891 --- /dev/null +++ b/cli/tests/testdata/npm/deno_run_special_chars_in_bin_name.out @@ -0,0 +1,4 @@ +this +is +a +test diff --git a/cli/tests/testdata/npm/registry/@denotest/special-chars-in-bin-name/1.0.0/main.mjs b/cli/tests/testdata/npm/registry/@denotest/special-chars-in-bin-name/1.0.0/main.mjs new file mode 100644 index 0000000000..0ae8e91903 --- /dev/null +++ b/cli/tests/testdata/npm/registry/@denotest/special-chars-in-bin-name/1.0.0/main.mjs @@ -0,0 +1,5 @@ +import process from "node:process"; + +for (const arg of process.argv.slice(2)) { + console.log(arg); +} diff --git a/cli/tests/testdata/npm/registry/@denotest/special-chars-in-bin-name/1.0.0/package.json b/cli/tests/testdata/npm/registry/@denotest/special-chars-in-bin-name/1.0.0/package.json new file mode 100644 index 0000000000..2dce473b57 --- /dev/null +++ b/cli/tests/testdata/npm/registry/@denotest/special-chars-in-bin-name/1.0.0/package.json @@ -0,0 +1,10 @@ +{ + "name": "@denotest/special-chars-in-bin-name", + "version": "1.0.0", + "type": "module", + "main": "main.mjs", + "bin": { + "\\foo\"": "main.mjs" + } + } + \ No newline at end of file diff --git a/ext/node/lib.rs b/ext/node/lib.rs index 7bf721f0ae..12d7b0b1e2 100644 --- a/ext/node/lib.rs +++ b/ext/node/lib.rs @@ -3,6 +3,7 @@ use deno_core::error::AnyError; use deno_core::located_script_name; use deno_core::op; +use deno_core::serde_json; use deno_core::JsRuntime; use once_cell::sync::Lazy; use std::collections::HashSet; @@ -430,7 +431,7 @@ pub fn initialize_runtime( maybe_binary_command_name: Option, ) -> Result<(), AnyError> { let argv0 = if let Some(binary_command_name) = maybe_binary_command_name { - format!("\"{}\"", binary_command_name) + serde_json::to_string(binary_command_name.as_str())? } else { "undefined".to_string() };