1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-25 08:39:09 -05:00

fix(ext/node): json encode binary command name (#18596)

Fixes https://github.com/denoland/deno/issues/18588
This commit is contained in:
Geert-Jan Zwiers 2023-04-06 01:46:21 +02:00 committed by GitHub
parent 36e8c8dfd7
commit a7e25b8126
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 1 deletions

View file

@ -689,6 +689,13 @@ itest!(deno_run_bin_esm {
http_server: true, 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 { itest!(deno_run_bin_no_ext {
args: "run -A --quiet npm:@denotest/bin/cli-no-ext this is a test", args: "run -A --quiet npm:@denotest/bin/cli-no-ext this is a test",
output: "npm/deno_run_no_ext.out", output: "npm/deno_run_no_ext.out",

View file

@ -0,0 +1,4 @@
this
is
a
test

View file

@ -0,0 +1,5 @@
import process from "node:process";
for (const arg of process.argv.slice(2)) {
console.log(arg);
}

View file

@ -0,0 +1,10 @@
{
"name": "@denotest/special-chars-in-bin-name",
"version": "1.0.0",
"type": "module",
"main": "main.mjs",
"bin": {
"\\foo\"": "main.mjs"
}
}

View file

@ -3,6 +3,7 @@
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::located_script_name; use deno_core::located_script_name;
use deno_core::op; use deno_core::op;
use deno_core::serde_json;
use deno_core::JsRuntime; use deno_core::JsRuntime;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use std::collections::HashSet; use std::collections::HashSet;
@ -430,7 +431,7 @@ pub fn initialize_runtime(
maybe_binary_command_name: Option<String>, maybe_binary_command_name: Option<String>,
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
let argv0 = if let Some(binary_command_name) = maybe_binary_command_name { 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 { } else {
"undefined".to_string() "undefined".to_string()
}; };