Avoid mutating the script argument in place

Mutating the argument in place, and in particular deleting the
`:executable` entry, leads to a bug when the same code path leading to
read_script_arguments is invoked twice, like in
https://github.com/Homebrew/homebrew-cask/pull/139749

This commit makes a shallow copy of the argument, so that it can be
safely mutated in the rest of the method.
This commit is contained in:
Luca Ongaro 2023-01-24 23:34:47 +01:00
parent 8f419180cf
commit f5765a73da

View File

@ -99,7 +99,12 @@ module Cask
description = key ? "#{stanza} #{key.inspect}" : stanza.to_s
# backward-compatible string value
arguments = { executable: arguments } if arguments.is_a?(String)
if arguments.is_a?(String)
arguments = { executable: arguments }
else
# Avoid mutating the original argument
arguments = arguments.dup
end
# key sanity
permitted_keys = [:args, :input, :executable, :must_succeed, :sudo, :print_stdout, :print_stderr]