diff options
-rw-r--r-- | lib/slop/parser.rb | 2 | ||||
-rw-r--r-- | test/parser_test.rb | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/slop/parser.rb b/lib/slop/parser.rb index 00b7e33..49d0230 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 ef09714..b729ee8 100644 --- a/test/parser_test.rb +++ b/test/parser_test.rb @@ -1,4 +1,5 @@ require 'test_helper' +require 'shellwords' describe Slop::Parser do before do @@ -28,6 +29,15 @@ describe Slop::Parser do assert_equal %w(=), @result.args end + it "parses flag=''" do + @options.string "--str" + @options.array "--arr", default: ["array"] + @result.parser.parse %(--str="" --arr="").shellsplit + + assert_equal "", @result[:str] + assert_equal [], @result[:arr] + end + it "parses arg with leading -" do @options.string "-t", "--text" @result.parser.parse %w(--name=bob --text --sometext) |