1
0
Fork 0
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:
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 { 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;

View file

@ -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",
}); });

View file

@ -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),