diff options
author | Lee Jarvis <leejarvis@fastmail.com> | 2018-03-12 13:54:56 +0000 |
---|---|---|
committer | Lee Jarvis <leejarvis@fastmail.com> | 2018-03-12 13:56:18 +0000 |
commit | d787c9a60b89e219d0f3791d48b2752b4d92af1d (patch) | |
tree | 8ae6103238d4c5c7cf583ae423c9bb0e2c6397b7 | |
parent | 1241a0ce6b3aca2eb4b31488976b85de9fd8e306 (diff) | |
download | slop-d787c9a60b89e219d0f3791d48b2752b4d92af1d.tar.gz |
Handle equals character for non-option valuespedantic-equals
If the string includes an equals char but doesn't look like it's a
possible candidate for a flag=value, we should ignore it
see #226
-rw-r--r-- | lib/slop/parser.rb | 4 | ||||
-rw-r--r-- | test/parser_test.rb | 5 |
2 files changed, 7 insertions, 2 deletions
diff --git a/lib/slop/parser.rb b/lib/slop/parser.rb index 463e75a..27e1c50 100644 --- a/lib/slop/parser.rb +++ b/lib/slop/parser.rb @@ -53,8 +53,8 @@ module Slop # support `foo=bar` orig_flag = flag.dup orig_arg = arg - if flag.include?("=") - flag, arg = flag.split("=") + if match = flag.match(/([^=]+)=([^=]+)/) + flag, arg = match.captures end if opt = try_process(flag, arg) diff --git a/test/parser_test.rb b/test/parser_test.rb index dcc3661..caee0dd 100644 --- a/test/parser_test.rb +++ b/test/parser_test.rb @@ -21,6 +21,11 @@ describe Slop::Parser do @result.parser.parse %w(--name=bob -p=123) assert_equal "bob", @result[:name] assert_equal 123, @result[:port] + + @options.string "--foo" + @result.parser.parse %w(--foo = =) + assert_equal "=", @result[:foo] + assert_equal %w(=), @result.args end it "parses arg with leading -" do |