File tree Expand file tree Collapse file tree 2 files changed +7
-32
lines changed
Expand file tree Collapse file tree 2 files changed +7
-32
lines changed Original file line number Diff line number Diff line change @@ -184,6 +184,9 @@ def validate_srv_hostname(hostname)
184184 if parts . any? ( &:empty? )
185185 raise_invalid_error! ( "Hostname cannot have consecutive dots: #{ hostname } " )
186186 end
187+ if parts . length == 0
188+ raise_invalid_error! ( "Hostname cannot be empty: #{ hostname } " )
189+ end
187190 end
188191
189192 # Obtains the TXT options of a host.
Original file line number Diff line number Diff line change 5656 end
5757 end
5858
59- context 'when the host in URI does not have {hostname}, {domainname} and {tld}' do
60-
61- let ( :string ) { "#{ scheme } #{ hosts } " }
62- let ( :hosts ) { '10gen.cc/' }
63-
64- it 'raises an error' do
65- expect { uri } . to raise_error ( Mongo ::Error ::InvalidURI )
66- end
67- end
68-
6959 context 'when the {tld} is empty' do
7060
7161 let ( :string ) { "#{ scheme } #{ hosts } " }
220210 expect { uri } . to raise_error ( Mongo ::Error ::InvalidURI )
221211 end
222212 end
223-
224- context 'mongodb+srv://example.com?w=1' do
225-
226- let ( :string ) { "#{ scheme } example.com?w=1" }
227-
228- it 'raises an error' do
229- expect { uri } . to raise_error ( Mongo ::Error ::InvalidURI )
230- end
231- end
232-
233- context 'mongodb+srv://example.com/?w' do
234-
235- let ( :string ) { "#{ scheme } example.com/?w" }
236-
237- it 'raises an error' do
238- expect { uri } . to raise_error ( Mongo ::Error ::InvalidURI )
239- end
240- end
241213 end
242214
243215 describe 'valid uris' do
13021274 'a'
13031275 end
13041276
1305- it 'raises an error' do
1306- expect { validate } . to raise_error ( Mongo :: Error :: InvalidURI )
1277+ it 'does not raise an error' do
1278+ expect { validate } . to_not raise_error
13071279 end
13081280 end
13091281
13131285 'a.b'
13141286 end
13151287
1316- it 'raises an error ' do
1317- expect { validate } . to raise_error ( Mongo :: Error :: InvalidURI )
1288+ it 'validates the hostname ' do
1289+ expect { validate } . not_to raise_error
13181290 end
13191291 end
13201292
You can’t perform that action at this time.
0 commit comments