Merge pull request #14416 from lucaong/avoid-mutating-script-argument

Avoid mutating the script argument in place
This commit is contained in:
Mike McQuaid 2023-01-25 13:26:00 +00:00 committed by GitHub
commit daecb93d22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 1 deletions

View File

@ -99,7 +99,12 @@ module Cask
description = key ? "#{stanza} #{key.inspect}" : stanza.to_s description = key ? "#{stanza} #{key.inspect}" : stanza.to_s
# backward-compatible string value # 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 # key sanity
permitted_keys = [:args, :input, :executable, :must_succeed, :sudo, :print_stdout, :print_stderr] permitted_keys = [:args, :input, :executable, :must_succeed, :sudo, :print_stdout, :print_stderr]

View File

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