diff --git a/lib/pg/connection.rb b/lib/pg/connection.rb index 01eb0c2cd..bf409eea3 100755 --- a/lib/pg/connection.rb +++ b/lib/pg/connection.rb @@ -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 /=/ diff --git a/spec/pg/connection_spec.rb b/spec/pg/connection_spec.rb index d0556730a..c07d13968 100755 --- a/spec/pg/connection_spec.rb +++ b/spec/pg/connection_spec.rb @@ -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 )