Skip to content

Commit ff89726

Browse files
committed
RUBY-756 Accept certain case sensitive options in uri
1 parent ff0457e commit ff89726

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/mongo/functional/uri_parser.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ class URIParser
125125
:wtimeoutms => lambda { |arg| arg.to_i }
126126
}
127127

128+
OPT_CASE_SENSITIVE = [ :authsource,
129+
:gssapiservicename,
130+
:replicaset,
131+
:w
132+
]
133+
128134
attr_reader :auths,
129135
:authmechanism,
130136
:authsource,
@@ -348,7 +354,8 @@ def parse_options(string_opts)
348354

349355
opts = CGI.parse(string_opts).inject({}) do |memo, (key, value)|
350356
value = value.first
351-
memo[key.downcase.to_sym] = value.strip.downcase
357+
key_sym = key.downcase.to_sym
358+
memo[key_sym] = OPT_CASE_SENSITIVE.include?(key_sym) ? value.strip : value.strip.downcase
352359
memo
353360
end
354361

test/functional/uri_test.rb

+12
Original file line numberDiff line numberDiff line change
@@ -327,4 +327,16 @@ def test_gssapi
327327
assert_equal true, parser.auths.first[:extra][:canonicalize_host_name]
328328
end
329329

330+
def test_opts_case_sensitivity
331+
# options gssapiservicename, authsource, replicaset, w should be case sensitive
332+
uri = "mongodb://localhost?gssapiServiceName=MongoDB;" +
333+
"authSource=FooBar;" +
334+
"replicaSet=Foo;" +
335+
"w=Majority"
336+
parser = Mongo::URIParser.new(uri)
337+
assert_equal 'MongoDB', parser.gssapiservicename
338+
assert_equal 'FooBar', parser.authsource
339+
assert_equal 'Foo', parser.replicaset
340+
assert_equal :Majority, parser.w
341+
end
330342
end

0 commit comments

Comments
 (0)