File tree Expand file tree Collapse file tree 2 files changed +21
-7
lines changed Expand file tree Collapse file tree 2 files changed +21
-7
lines changed Original file line number Diff line number Diff line change 16
16
# limitations under the License.
17
17
# ++
18
18
19
+ require 'cgi'
20
+
19
21
module Mongo
20
22
class URIParser
21
23
@@ -260,8 +262,12 @@ def parse_options(string_opts, extra_opts={})
260
262
261
263
return if string_opts . empty? && extra_opts . empty?
262
264
263
- opts = string_opts . split ( /&|;/ ) . inject ( { } ) do |memo , kv |
264
- key , value = kv . split ( '=' )
265
+ if string_opts . include? ( ';' ) and string_opts . include? ( '&' )
266
+ raise MongoArgumentError , "must not mix URL separators ; and &"
267
+ end
268
+
269
+ opts = CGI . parse ( string_opts ) . inject ( { } ) do |memo , ( key , value ) |
270
+ value = value . first
265
271
memo [ key . downcase . to_sym ] = value . strip . downcase
266
272
memo
267
273
end
Original file line number Diff line number Diff line change @@ -79,11 +79,19 @@ def test_opts_with_amp_separator
79
79
assert parser . safe
80
80
end
81
81
82
- #def test_opts_made_invalid_by_mixed_separators
83
- # assert_raise_error ArgumentError, "invalid data of application/x-www-form-urlencoded (replicaset=foo;bar&slaveok=true&safe=true)" do
84
- # Mongo::URIParser.new('mongodb://localhost:27018?replicaset=foo;bar&slaveok=true&safe=true')
85
- # end
86
- #end
82
+ def test_opts_with_uri_encoded_stuff
83
+ parser = Mongo ::URIParser . new ( 'mongodb://localhost:27018?connect=%64%69%72%65%63%74&slaveok=%74%72%75%65&safe=true' )
84
+ assert_equal 'direct' , parser . connect
85
+ assert parser . direct?
86
+ assert parser . slaveok
87
+ assert parser . safe
88
+ end
89
+
90
+ def test_opts_made_invalid_by_mixed_separators
91
+ assert_raise_error MongoArgumentError , "must not mix URL separators ; and &" do
92
+ Mongo ::URIParser . new ( 'mongodb://localhost:27018?replicaset=foo;bar&slaveok=true&safe=true' )
93
+ end
94
+ end
87
95
88
96
def test_opts_safe
89
97
parser = Mongo ::URIParser . new ( 'mongodb://localhost:27018?safe=true;w=2;journal=true;fsync=true;wtimeoutMS=200' )
You can’t perform that action at this time.
0 commit comments