Skip to content

Commit

Permalink
Check if the argument for #Connection is an URI
Browse files Browse the repository at this point in the history
Previously the code checked if the argument
contained an URI instead of being one. This
caused some connection strings being mis-
dected as connection URI's.

fixes #265
  • Loading branch information
jjoos committed Sep 5, 2017
1 parent ec083d1 commit 4f13f18
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/pg/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def self::parse_connect_args( *args )

if args.length == 1
case args.first
when URI, URI.regexp
when URI, /\A#{URI.regexp}\z/
uri = URI(args.first)
options.merge!( Hash[URI.decode_www_form( uri.query )] ) if uri.query
when /=/
Expand Down
13 changes: 13 additions & 0 deletions spec/pg/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@
expect( described_class.parse_connect_args ).to eq( '' )
end

it "connects successfully with connection string" do
conninfo_with_colon_in_password = "host=localhost user=a port=555 dbname=test password=a:a"

string = described_class.parse_connect_args( conninfo_with_colon_in_password )

expect( string ).to be_a( String )
expect( string ).to match( %r{(^|\s)user=a} )
expect( string ).to match( %r{(^|\s)password=a:a} )
expect( string ).to match( %r{(^|\s)host=localhost} )
expect( string ).to match( %r{(^|\s)port=555} )
expect( string ).to match( %r{(^|\s)dbname=test} )
end

it "connects successfully with connection string" do
tmpconn = described_class.connect( @conninfo )
expect( tmpconn.status ).to eq( PG::CONNECTION_OK )
Expand Down

0 comments on commit 4f13f18

Please sign in to comment.