diff --git a/lib/yawpa.rb b/lib/yawpa.rb index 385d4b7..c49b195 100644 --- a/lib/yawpa.rb +++ b/lib/yawpa.rb @@ -129,10 +129,10 @@ module Yawpa short_idx += 1 end elsif flags[:posix_order] - args = params[i, params.length] + args = params[i, params.length].map(&:dup) break else - args << params[i] + args << params[i].dup end i += 1 end @@ -161,7 +161,7 @@ module Yawpa while n_gathered < nargs.last and index < params.length and params[index][0] != '-' do - result << params[index] + result << params[index].dup index += 1 num_indices_used += 1 n_gathered += 1 diff --git a/spec/yawpa_spec.rb b/spec/yawpa_spec.rb index 30a024e..bbf067b 100644 --- a/spec/yawpa_spec.rb +++ b/spec/yawpa_spec.rb @@ -230,5 +230,32 @@ describe Yawpa do expect(opts).to eq(push: false, pull: true) expect(args).to eq(%w[arg]) end + + it "returns non-frozen strings" do + options = { + o1: {nargs: 1, short: "1"}, + o2: {nargs: 1, short: "2"}, + o3: {nargs: 1, short: "3"}, + o4: {nargs: 1, short: "4"}, + } + + arguments = %w[--o1=one --o2 two -3 three -4four arg].map(&:freeze) + + opts, args = Yawpa.parse(arguments, options) + expect(opts[:o1].frozen?).to be_falsey + expect{opts[:o1].sub!(/./, '-')}.to_not raise_error + expect(opts[:o2].frozen?).to be_falsey + expect{opts[:o2].sub!(/./, '-')}.to_not raise_error + expect(opts[:o3].frozen?).to be_falsey + expect{opts[:o3].sub!(/./, '-')}.to_not raise_error + expect(opts[:o4].frozen?).to be_falsey + expect{opts[:o4].sub!(/./, '-')}.to_not raise_error + expect(args[0].frozen?).to be_falsey + expect{args[0].sub!(/./, '-')}.to_not raise_error + + opts, args = Yawpa.parse(arguments, options, posix_order: true) + expect(args[0].frozen?).to be_falsey + expect{args[0].sub!(/./, '-')}.to_not raise_error + end end end