Skip to content

RUBY-951 Ensure that driver conforms to Connection String specification #643

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/mongo/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class Error < StandardError
require 'mongo/error/invalid_signature'
require 'mongo/error/invalid_update_document'
require 'mongo/error/invalid_uri'
require 'mongo/error/invalid_uri_option'
require 'mongo/error/max_bson_size'
require 'mongo/error/max_message_size'
require 'mongo/error/multi_index_drop'
Expand Down
38 changes: 0 additions & 38 deletions lib/mongo/error/invalid_uri_option.rb

This file was deleted.

17 changes: 12 additions & 5 deletions lib/mongo/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module Mongo
#
# @since 2.0.0
class URI
include Loggable

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

# Option Regex: notably only matches the ampersand separator and does
# Option Regex: only matches the ampersand separator and does
# not allow for semicolon to be used to separate options.
#
# @since 2.0.0
Expand Down Expand Up @@ -123,7 +124,8 @@ class URI
#
# @since 2.0.0
def initialize(string)
@match = string.match(URI)
@string = string
@match = @string.match(URI)
raise Error::InvalidURI.new(string) unless @match
end

Expand Down Expand Up @@ -210,8 +212,13 @@ def options
parsed_options.split('&').reduce({}) do |options, option|
key, value = option.split('=')
strategy = OPTION_MAP[key]
raise Error::InvalidURIOption.new(key) if strategy.nil?
add_option(strategy, value, options)
if strategy.nil?
log_warn([
"Unsupported URI option '#{key}' on URI '#{@string}'. It will be ignored."
])
else
add_option(strategy, value, options)
end
options
end
end
Expand Down Expand Up @@ -243,7 +250,7 @@ def self.option(uri_key, name, extra = {})

# Write Options
option 'w', :w, :group => :write
option 'j', :j, :group => :write
option 'journal', :j, :group => :write
option 'fsync', :fsync, :group => :write
option 'wtimeoutMS', :timeout, :group => :write

Expand Down
34 changes: 25 additions & 9 deletions spec/mongo/uri_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@
describe '#database' do
let(:servers) { 'localhost' }
let(:string) { "#{scheme}#{servers}/#{db}" }
let(:db) { TEST_DB }
let(:db) { 'auth-db' }

context 'database provided' do
it 'returns the database name' do
expect(uri.database).to eq(TEST_DB)
expect(uri.database).to eq(db)
end
end
end
Expand Down Expand Up @@ -171,7 +171,7 @@
end

context 'journal' do
let(:options) { 'j=true' }
let(:options) { 'journal=true' }
let(:concern) { { :j => true } }

it 'sets the write concern options' do
Expand Down Expand Up @@ -248,7 +248,7 @@
end
end

context 'read preferece tags provided' do
context 'read preference tags provided' do

context 'single read preference tag set' do
let(:options) do
Expand Down Expand Up @@ -505,12 +505,28 @@

context 'when an invalid option is provided' do

let(:options) { 'iDontKnow=10' }
let(:options) { 'invalidOption=10' }

it 'raises an exception' do
expect {
uri.options
}.to raise_error(Mongo::Error::InvalidURIOption)
let(:uri_options) do
uri.options
end

it 'does not raise an exception' do
expect(uri_options).to be_empty
end

context 'when an invalid option is combined with valid options' do

let(:options) { 'invalidOption=10&waitQueueTimeoutMS=500&ssl=true' }

it 'does not raise an exception' do
expect(uri_options).not_to be_empty
end

it 'sets the valid options' do
expect(uri_options[:wait_queue_timeout]).to eq(0.5)
expect(uri_options[:ssl]).to be true
end
end
end
end
Expand Down