Skip to content

Commit 1afa0a5

Browse files
authored
RUBY-3329 Connection String: make delimiting slash between hosts and options optional (#2824)
1 parent 9228f5f commit 1afa0a5

File tree

4 files changed

+13
-23
lines changed

4 files changed

+13
-23
lines changed

Diff for: lib/mongo/uri.rb

-4
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,6 @@ def parse!(remaining)
377377
raise_invalid_error!("Options contain an unescaped question mark (?), or the database name contains a question mark and was not escaped")
378378
end
379379

380-
if options && !hosts_and_db.index('/')
381-
raise_invalid_error!("MongoDB URI must have a slash (/) after the hosts if options are given")
382-
end
383-
384380
hosts, db = hosts_and_db.split('/', 2)
385381
if db && db.index('/')
386382
raise_invalid_error!("Database name contains an unescaped slash (/): #{db}")

Diff for: spec/mongo/uri_spec.rb

-9
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,6 @@
266266
end
267267
end
268268

269-
context 'no slash after hosts, and options' do
270-
271-
let(:string) { 'mongodb://example.com?tls=true' }
272-
273-
it 'raises an error' do
274-
expect { uri }.to raise_error(Mongo::Error::InvalidURI, %r,MongoDB URI must have a slash \(/\) after the hosts if options are given,)
275-
end
276-
end
277-
278269
context 'mongodb://example.com/?w' do
279270

280271
let(:string) { 'mongodb://example.com/?w' }

Diff for: spec/spec_tests/data/connection_string/invalid-uris.yml

-10
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,6 @@ tests:
143143
hosts: ~
144144
auth: ~
145145
options: ~
146-
-
147-
description: "Missing delimiting slash between hosts and options"
148-
uri: "mongodb://example.com?w=1"
149-
valid: false
150-
warning: ~
151-
hosts: ~
152-
auth: ~
153-
options: ~
154146
-
155147
description: "Incomplete key value pair for option"
156148
uri: "mongodb://example.com/?w"
@@ -257,5 +249,3 @@ tests:
257249
hosts: ~
258250
auth: ~
259251
options: ~
260-
261-

Diff for: spec/spec_tests/data/connection_string/valid-options.yml

+13
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,16 @@ tests:
1515
db: "admin"
1616
options:
1717
authmechanism: "MONGODB-CR"
18+
-
19+
description: "Missing delimiting slash between hosts and options"
20+
uri: "mongodb://example.com?tls=true"
21+
valid: true
22+
warning: false
23+
hosts:
24+
-
25+
type: "hostname"
26+
host: "example.com"
27+
port: ~
28+
auth: ~
29+
options:
30+
tls: true

0 commit comments

Comments
 (0)