diff --git a/lib/thor/parser/arguments.rb b/lib/thor/parser/arguments.rb index fc887ac51..05c1a659c 100644 --- a/lib/thor/parser/arguments.rb +++ b/lib/thor/parser/arguments.rb @@ -30,7 +30,11 @@ def initialize(arguments = []) arguments.each do |argument| if !argument.default.nil? - @assigns[argument.human_name] = argument.default + begin + @assigns[argument.human_name] = argument.default.dup + rescue TypeError # Compatibility shim for un-dup-able Fixnum in Ruby < 2.4 + @assigns[argument.human_name] = argument.default + end elsif argument.required? @non_assigned_required << argument end diff --git a/spec/parser/options_spec.rb b/spec/parser/options_spec.rb index 843119d78..12dbda36a 100644 --- a/spec/parser/options_spec.rb +++ b/spec/parser/options_spec.rb @@ -302,11 +302,10 @@ def remaining "Expected '--fruit' to be one of #{enum.join(', ')}; got orange") end - it "allows multiple values if repeatable is specified" do - create :foo => Thor::Option.new("foo", :type => :string, :repeatable => true) - + it "does not erroneously mutate defaults" do + create :foo => Thor::Option.new("foo", :type => :string, :repeatable => true, :required => false, :default => []) expect(parse("--foo=bar", "--foo", "12")["foo"]).to eq(["bar", "12"]) - expect(parse("--foo", "13", "--foo", "14")["foo"]).to eq(["bar", "12", "13", "14"]) + expect(@opt.instance_variable_get(:@switches)["--foo"].default).to eq([]) end end