Commit a8357595 authored by Leo Gordon's avatar Leo Gordon Committed by Matthieu Muffato
Browse files

changes to allow no trailing slash in database-instance URLs (updated not to...

changes to allow no trailing slash in database-instance URLs (updated not to assume dbname is always defined)
parent c3d45fed
......@@ -103,13 +103,13 @@ sub parse {
} # /if OLD format
if( ($dbconn_part, $driver, $user, $pass, $host, $port, $dbname, $query_part, $conn_param_string) =
$url =~ m{^((\w+)://(?:(\w+)(?:\:([^/\@]*))?\@)?(?:([\w\-\.]+)(?:\:(\d*))?)?/([/~\w\-\.]*))?(?:\?(\w+=[\w\[\]\{\}]*(?:&\w+=[\w\[\]\{\}]*)*))?(;\w+=\w+(?:;\w+=\w+)*)?$} ) {
$url =~ m{^((\w+)://(?:(\w+)(?:\:([^/\@]*))?\@)?(?:([\w\-\.]+)(?:\:(\d*))?)?(?:/([/~\w\-\.]*))?)?(?:\?(\w+=[\w\[\]\{\}]*(?:&\w+=[\w\[\]\{\}]*)*))?(;\w+=\w+(?:;\w+=\w+)*)?$} ) {
my %conn_params = split(/[;=]/, 'type=hive;disconnect_when_inactive=0'.($conn_param_string // '') );
my $query_params = $query_part ? { split(/[&=]/, $query_part ) } : undef;
my $exception_from_NEW_format;
if(!$query_params and ($driver eq 'mysql' or $driver eq 'pgsql') and $dbname=~m{/}) { # a special case of multipart dbpath hints at the OLD format (or none at all)
if(!$query_params and ($driver eq 'mysql' or $driver eq 'pgsql') and $dbname and $dbname=~m{/}) { # a special case of multipart dbpath hints at the OLD format (or none at all)
$query_params = { 'object_type' => 'NakedTable' };
$exception_from_NEW_format = 1;
......@@ -118,7 +118,7 @@ sub parse {
if($query_params->{'logic_name'}) {
$object_type = 'Analysis';
if($dbname=~m{^([/~\w\-\.]*)/analysis$}) {
if($dbname and $dbname=~m{^([/~\w\-\.]*)/analysis$}) {
$exception_from_NEW_format = 1;
}
} elsif($query_params->{'accu_name'}) { # we don't require $query_params->{'accu_address'} to support scalar accu
......@@ -127,7 +127,7 @@ sub parse {
$object_type = 'NakedTable';
} elsif($query_params->{'insertion_method'}) {
$object_type = 'NakedTable';
if($dbname=~m{^([/~\w\-\.]*)/(\w+)$}) {
if($dbname and $dbname=~m{^([/~\w\-\.]*)/(\w+)$}) {
$exception_from_NEW_format = 1;
}
}
......
......@@ -258,4 +258,63 @@ BEGIN {
is_deeply( $url_hash->{'query_params'}, { 'object_type' => 'NakedTable', 'table_name' => 'foreign_table' }, 'query_params hash correct' );
}
{ # NEW style database server URL (db_name-less) with a trailing slash:
my $url = 'mysql://who:secret@where.co.uk:12345/';
my $url_hash = Bio::EnsEMBL::Hive::Utils::URL::parse( $url );
ok($url_hash, "parser returned something for $url");
isa_ok( $url_hash, 'HASH' );
is( $url_hash->{'driver'}, 'mysql', 'driver correct' );
is( $url_hash->{'user'}, 'who', 'user correct' );
is( $url_hash->{'pass'}, 'secret', 'password correct' );
is( $url_hash->{'host'}, 'where.co.uk', 'hostname correct' );
is( $url_hash->{'port'}, 12345, 'port number correct' );
is( $url_hash->{'dbname'}, '', 'database name correct' );
}
{ # NEW style database server URL (db_name-less) without a trailing slash:
my $url = 'mysql://who:secret@where.co.uk:12345';
my $url_hash = Bio::EnsEMBL::Hive::Utils::URL::parse( $url );
ok($url_hash, "parser returned something for $url");
isa_ok( $url_hash, 'HASH' );
is( $url_hash->{'driver'}, 'mysql', 'driver correct' );
is( $url_hash->{'user'}, 'who', 'user correct' );
is( $url_hash->{'pass'}, 'secret', 'password correct' );
is( $url_hash->{'host'}, 'where.co.uk', 'hostname correct' );
is( $url_hash->{'port'}, 12345, 'port number correct' );
is( $url_hash->{'dbname'}, undef, 'database name correct' );
}
{ # NEW style sqlite URL with an absolute path:
my $url = 'sqlite:////var/folders/1k/qdbfbdls6nn98pqzbdkcsnfc0000gn/T/eR81O_qhbH/ehive_server_pipeline_db?logic_name=part_multiply';
my $url_hash = Bio::EnsEMBL::Hive::Utils::URL::parse( $url );
ok($url_hash, "parser returned something for $url");
isa_ok( $url_hash, 'HASH' );
is( $url_hash->{'driver'}, 'sqlite', 'driver correct' );
is( $url_hash->{'dbname'}, '/var/folders/1k/qdbfbdls6nn98pqzbdkcsnfc0000gn/T/eR81O_qhbH/ehive_server_pipeline_db', 'database path correct' );
is_deeply( $url_hash->{'query_params'}, { 'object_type' => 'Analysis', 'logic_name' => 'part_multiply' }, 'query params correct' );
}
{ # NEW style sqlite URL with a relative path:
my $url = 'sqlite:///relative/path/to/ehive_server_pipeline_db?logic_name=part_multiply';
my $url_hash = Bio::EnsEMBL::Hive::Utils::URL::parse( $url );
ok($url_hash, "parser returned something for $url");
isa_ok( $url_hash, 'HASH' );
is( $url_hash->{'driver'}, 'sqlite', 'driver correct' );
is( $url_hash->{'dbname'}, 'relative/path/to/ehive_server_pipeline_db', 'database path correct' );
is_deeply( $url_hash->{'query_params'}, { 'object_type' => 'Analysis', 'logic_name' => 'part_multiply' }, 'query params correct' );
}
done_testing();
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment