From 8ae2eae0bf0b09346589bb57bdb13c86d96b6e0f Mon Sep 17 00:00:00 2001 From: Connor Garvey Date: Thu, 10 Mar 2022 17:04:15 -0800 Subject: Handle strings containing = --- lib/slop/parser.rb | 2 +- test/parser_test.rb | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/slop/parser.rb b/lib/slop/parser.rb index 49d0230..3c2c9c6 100644 --- a/lib/slop/parser.rb +++ b/lib/slop/parser.rb @@ -52,7 +52,7 @@ module Slop # support `foo=bar` orig_flag = flag.dup - if match = flag.match(/([^=]+)=([^=]*)/) + if match = flag.match(/([^=]+)=(.*)/) flag, arg = match.captures end diff --git a/test/parser_test.rb b/test/parser_test.rb index b729ee8..bbdc4a9 100644 --- a/test/parser_test.rb +++ b/test/parser_test.rb @@ -17,16 +17,25 @@ describe Slop::Parser do assert_equal ["-v", "--name", "lee"], @parser.arguments end - it "parses flag=argument" do - @options.integer "-p", "--port" - @result.parser.parse %w(--name=bob -p=123) - assert_equal "bob", @result[:name] - assert_equal 123, @result[:port] + describe "for flag=argument" do + it "parses names and values" do + @options.integer "-p", "--port" + @result.parser.parse %w(--name=bob -p=123) + assert_equal "bob", @result[:name] + assert_equal 123, @result[:port] + end - @options.string "--foo" - @result.parser.parse %w(--foo = =) - assert_equal "=", @result[:foo] - assert_equal %w(=), @result.args + it "treats an = separated by a space as a value" do + @options.string "--foo" + @result.parser.parse %w(--foo = =) + assert_equal "=", @result[:foo] + assert_equal %w(=), @result.args + end + + it "includes = in strings" do + @result.parser.parse(%w(--name=b=b)) + assert_equal "b=b", @result[:name] + end end it "parses flag=''" do -- cgit v1.2.1