Skip to content

Commit 29677b1

Browse files
committed
Merge pull request #456 from dgorst/master
Issue #455 - only allow a hash key to be specified once
2 parents 55cc2ec + 22bea23 commit 29677b1

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/thor/parser/arguments.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def parse_hash(name)
9999

100100
while current_is_value? && peek.include?(":")
101101
key, value = shift.split(":", 2)
102+
fail MalformattedArgumentError, "You can't specify '#{key}' more than once in option '#{name}'; got #{key}:#{hash[key]} and #{key}:#{value}" if hash.include? key
102103
hash[key] = value
103104
end
104105
hash

spec/parser/options_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def remaining
293293
enum = %w[apple banana]
294294
create :fruit => Thor::Option.new("fruit", :type => :string, :enum => enum)
295295
expect { parse("--fruit", "orange") }.to raise_error(Thor::MalformattedArgumentError,
296-
"Expected '--fruit' to be one of #{enum.join(', ')}; got orange")
296+
"Expected '--fruit' to be one of #{enum.join(', ')}; got orange")
297297
end
298298
end
299299

@@ -364,6 +364,10 @@ def remaining
364364
it "must not mix values with other switches" do
365365
expect(parse("--attributes", "name:string", "age:integer", "--baz", "cool")["attributes"]).to eq("name" => "string", "age" => "integer")
366366
end
367+
368+
it "must not allow the same hash key to be specified multiple times" do
369+
expect {parse("--attributes", "name:string", "name:integer")}.to raise_error(Thor::MalformattedArgumentError, "You can't specify 'name' more than once in option '--attributes'; got name:string and name:integer")
370+
end
367371
end
368372

369373
describe "with :array type" do

0 commit comments

Comments
 (0)