diff --git a/Library/Homebrew/cask/artifact/abstract_artifact.rb b/Library/Homebrew/cask/artifact/abstract_artifact.rb index 25b6f02833..14d203ee4b 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) + arguments = if arguments.is_a?(String) + { executable: arguments } + else + # Avoid mutating the original argument + arguments.dup + end # key sanity permitted_keys = [:args, :input, :executable, :must_succeed, :sudo, :print_stdout, :print_stderr] diff --git a/Library/Homebrew/test/cask/artifact/abstract_artifact_spec.rb b/Library/Homebrew/test/cask/artifact/abstract_artifact_spec.rb new file mode 100644 index 0000000000..24e35e969d --- /dev/null +++ b/Library/Homebrew/test/cask/artifact/abstract_artifact_spec.rb @@ -0,0 +1,29 @@ +# typed: false +# frozen_string_literal: true + +describe Cask::Artifact::AbstractArtifact, :cask do + describe ".read_script_arguments" do + let(:stanza) { :installer } + + it "accepts a string, and uses it as the executable" do + arguments = "something" + + expect(described_class.read_script_arguments(arguments, stanza)).to eq(["something", {}]) + end + + it "accepts a hash with an executable" do + arguments = { executable: "something" } + + expect(described_class.read_script_arguments(arguments, stanza)).to eq(["something", {}]) + end + + it "does not mutate the original arguments in place" do + arguments = { executable: "something" } + clone = arguments.dup + + described_class.read_script_arguments(arguments, stanza) + + expect(arguments).to eq(clone) + end + end +end