Skip to content

Commit bc55f82

Browse files
committed
Merge pull request #643 from estolfo/RUBY-951-uri
RUBY-951 Ensure that driver conforms to Connection String specification
2 parents 08d8433 + e90a001 commit bc55f82

File tree

4 files changed

+37
-53
lines changed

4 files changed

+37
-53
lines changed

lib/mongo/error.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ class Error < StandardError
8080
require 'mongo/error/invalid_signature'
8181
require 'mongo/error/invalid_update_document'
8282
require 'mongo/error/invalid_uri'
83-
require 'mongo/error/invalid_uri_option'
8483
require 'mongo/error/max_bson_size'
8584
require 'mongo/error/max_message_size'
8685
require 'mongo/error/multi_index_drop'

lib/mongo/error/invalid_uri_option.rb

Lines changed: 0 additions & 38 deletions
This file was deleted.

lib/mongo/uri.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module Mongo
2727
#
2828
# @since 2.0.0
2929
class URI
30+
include Loggable
3031

3132
# Scheme Regex: non-capturing, matches scheme.
3233
#
@@ -69,7 +70,7 @@ class URI
6970
# @since 2.0.0
7071
DATABASE = %r{(?:/([^/\.\ "*<>:\|\?]*))?}.freeze
7172

72-
# Option Regex: notably only matches the ampersand separator and does
73+
# Option Regex: only matches the ampersand separator and does
7374
# not allow for semicolon to be used to separate options.
7475
#
7576
# @since 2.0.0
@@ -123,7 +124,8 @@ class URI
123124
#
124125
# @since 2.0.0
125126
def initialize(string)
126-
@match = string.match(URI)
127+
@string = string
128+
@match = @string.match(URI)
127129
raise Error::InvalidURI.new(string) unless @match
128130
end
129131

@@ -210,8 +212,13 @@ def options
210212
parsed_options.split('&').reduce({}) do |options, option|
211213
key, value = option.split('=')
212214
strategy = OPTION_MAP[key]
213-
raise Error::InvalidURIOption.new(key) if strategy.nil?
214-
add_option(strategy, value, options)
215+
if strategy.nil?
216+
log_warn([
217+
"Unsupported URI option '#{key}' on URI '#{@string}'. It will be ignored."
218+
])
219+
else
220+
add_option(strategy, value, options)
221+
end
215222
options
216223
end
217224
end
@@ -243,7 +250,7 @@ def self.option(uri_key, name, extra = {})
243250

244251
# Write Options
245252
option 'w', :w, :group => :write
246-
option 'j', :j, :group => :write
253+
option 'journal', :j, :group => :write
247254
option 'fsync', :fsync, :group => :write
248255
option 'wtimeoutMS', :timeout, :group => :write
249256

spec/mongo/uri_spec.rb

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@
129129
describe '#database' do
130130
let(:servers) { 'localhost' }
131131
let(:string) { "#{scheme}#{servers}/#{db}" }
132-
let(:db) { TEST_DB }
132+
let(:db) { 'auth-db' }
133133

134134
context 'database provided' do
135135
it 'returns the database name' do
136-
expect(uri.database).to eq(TEST_DB)
136+
expect(uri.database).to eq(db)
137137
end
138138
end
139139
end
@@ -171,7 +171,7 @@
171171
end
172172

173173
context 'journal' do
174-
let(:options) { 'j=true' }
174+
let(:options) { 'journal=true' }
175175
let(:concern) { { :j => true } }
176176

177177
it 'sets the write concern options' do
@@ -248,7 +248,7 @@
248248
end
249249
end
250250

251-
context 'read preferece tags provided' do
251+
context 'read preference tags provided' do
252252

253253
context 'single read preference tag set' do
254254
let(:options) do
@@ -505,12 +505,28 @@
505505

506506
context 'when an invalid option is provided' do
507507

508-
let(:options) { 'iDontKnow=10' }
508+
let(:options) { 'invalidOption=10' }
509509

510-
it 'raises an exception' do
511-
expect {
512-
uri.options
513-
}.to raise_error(Mongo::Error::InvalidURIOption)
510+
let(:uri_options) do
511+
uri.options
512+
end
513+
514+
it 'does not raise an exception' do
515+
expect(uri_options).to be_empty
516+
end
517+
518+
context 'when an invalid option is combined with valid options' do
519+
520+
let(:options) { 'invalidOption=10&waitQueueTimeoutMS=500&ssl=true' }
521+
522+
it 'does not raise an exception' do
523+
expect(uri_options).not_to be_empty
524+
end
525+
526+
it 'sets the valid options' do
527+
expect(uri_options[:wait_queue_timeout]).to eq(0.5)
528+
expect(uri_options[:ssl]).to be true
529+
end
514530
end
515531
end
516532
end

0 commit comments

Comments
 (0)