1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

fix: Deno.run - do not modify user provided cmd array (#14109)

This commit is contained in:
David Sherret 2022-03-25 08:17:13 -04:00 committed by Luca Casonato
parent 89f1842977
commit a5c0deb73b
No known key found for this signature in database
GPG key ID: 01A83EB62563811F
3 changed files with 9 additions and 3 deletions

View file

@ -2398,7 +2398,7 @@ declare namespace Deno {
export interface RunOptions {
/** Arguments to pass. Note, the first element needs to be a path to the
* binary */
cmd: string[] | [URL, ...string[]];
cmd: readonly string[] | [URL, ...string[]];
cwd?: string;
env?: {
[key: string]: string;

View file

@ -21,7 +21,12 @@ Deno.test(
{ permissions: { run: true, read: true } },
async function runSuccess() {
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",
stderr: "null",
});

View file

@ -9,6 +9,7 @@
const { assert } = window.__bootstrap.infra;
const {
ArrayPrototypeMap,
ArrayPrototypeSlice,
TypeError,
isNaN,
ObjectEntries,
@ -110,7 +111,7 @@
stdin = "inherit",
}) {
if (cmd[0] != null) {
cmd[0] = pathFromURL(cmd[0]);
cmd = [pathFromURL(cmd[0]), ...ArrayPrototypeSlice(cmd, 1)];
}
const res = opRun({
cmd: ArrayPrototypeMap(cmd, String),