summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLee Jarvis <leejarvis@fastmail.com>2022-03-26 08:58:45 +0000
committerGitHub <noreply@github.com>2022-03-26 08:58:45 +0000
commit63d69edc1642589082306da5abc3bcf2a1df2ef7 (patch)
treec237da22a194f9ae5e0a6af7ae894b5318c92d48
parent0e1d8d0168fc6a6b647cecda0b73d97d1484a563 (diff)
parent8ae2eae0bf0b09346589bb57bdb13c86d96b6e0f (diff)
downloadslop-63d69edc1642589082306da5abc3bcf2a1df2ef7.tar.gz
Merge pull request #275 from ConnorWGarvey/equals
Handle strings containing =
-rw-r--r--lib/slop/parser.rb2
-rw-r--r--test/parser_test.rb27
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