mirror of
https://github.com/denoland/deno.git
synced 2024-11-28 16:20:57 -05:00
fix: Deno.run
- do not modify user provided cmd
array (#14109)
This commit is contained in:
parent
89f1842977
commit
a5c0deb73b
3 changed files with 9 additions and 3 deletions
2
cli/dts/lib.deno.ns.d.ts
vendored
2
cli/dts/lib.deno.ns.d.ts
vendored
|
@ -2398,7 +2398,7 @@ declare namespace Deno {
|
||||||
export interface RunOptions {
|
export interface RunOptions {
|
||||||
/** Arguments to pass. Note, the first element needs to be a path to the
|
/** Arguments to pass. Note, the first element needs to be a path to the
|
||||||
* binary */
|
* binary */
|
||||||
cmd: string[] | [URL, ...string[]];
|
cmd: readonly string[] | [URL, ...string[]];
|
||||||
cwd?: string;
|
cwd?: string;
|
||||||
env?: {
|
env?: {
|
||||||
[key: string]: string;
|
[key: string]: string;
|
||||||
|
|
|
@ -21,7 +21,12 @@ Deno.test(
|
||||||
{ permissions: { run: true, read: true } },
|
{ permissions: { run: true, read: true } },
|
||||||
async function runSuccess() {
|
async function runSuccess() {
|
||||||
const p = Deno.run({
|
const p = Deno.run({
|
||||||
cmd: [Deno.execPath(), "eval", "console.log('hello world')"],
|
// freeze the array to ensure it's not modified
|
||||||
|
cmd: Object.freeze([
|
||||||
|
Deno.execPath(),
|
||||||
|
"eval",
|
||||||
|
"console.log('hello world')",
|
||||||
|
]),
|
||||||
stdout: "piped",
|
stdout: "piped",
|
||||||
stderr: "null",
|
stderr: "null",
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
const { assert } = window.__bootstrap.infra;
|
const { assert } = window.__bootstrap.infra;
|
||||||
const {
|
const {
|
||||||
ArrayPrototypeMap,
|
ArrayPrototypeMap,
|
||||||
|
ArrayPrototypeSlice,
|
||||||
TypeError,
|
TypeError,
|
||||||
isNaN,
|
isNaN,
|
||||||
ObjectEntries,
|
ObjectEntries,
|
||||||
|
@ -110,7 +111,7 @@
|
||||||
stdin = "inherit",
|
stdin = "inherit",
|
||||||
}) {
|
}) {
|
||||||
if (cmd[0] != null) {
|
if (cmd[0] != null) {
|
||||||
cmd[0] = pathFromURL(cmd[0]);
|
cmd = [pathFromURL(cmd[0]), ...ArrayPrototypeSlice(cmd, 1)];
|
||||||
}
|
}
|
||||||
const res = opRun({
|
const res = opRun({
|
||||||
cmd: ArrayPrototypeMap(cmd, String),
|
cmd: ArrayPrototypeMap(cmd, String),
|
||||||
|
|
Loading…
Reference in a new issue