From f5765a73da0b9535c0b640f3e405f377c7b934e1 Mon Sep 17 00:00:00 2001 From: Luca Ongaro Date: Tue, 24 Jan 2023 23:34:47 +0100 Subject: [PATCH] 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. --- Library/Homebrew/cask/artifact/abstract_artifact.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cask/artifact/abstract_artifact.rb b/Library/Homebrew/cask/artifact/abstract_artifact.rb index 25b6f02833..047093c357 100644 --- a/Library/Homebrew/cask/artifact/abstract_artifact.rb +++ b/Library/Homebrew/cask/artifact/abstract_artifact.rb @@ -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]