@@ -25,13 +25,17 @@ fn parse_uri(uri: &str) -> Result<Box<dyn Storable>> {
25
25
26
26
// extract storage string
27
27
let idx = uri. find ( "://" ) . ok_or ( Error :: InvalidUri ) ?;
28
- let part = & uri[ ..idx] ;
28
+ let loc = & uri[ idx + 3 ..] ;
29
+ if loc. is_empty ( ) {
30
+ return Err ( Error :: InvalidUri ) ;
31
+ }
32
+ let storage_type = & uri[ ..idx] ;
29
33
30
- match part {
34
+ match storage_type {
31
35
"mem" => {
32
36
#[ cfg( feature = "storage-mem" ) ]
33
37
{
34
- Ok ( Box :: new ( super :: mem:: MemStorage :: new ( ) ) )
38
+ Ok ( Box :: new ( super :: mem:: MemStorage :: new ( loc ) ) )
35
39
}
36
40
#[ cfg( not( feature = "storage-mem" ) ) ]
37
41
{
@@ -41,7 +45,7 @@ fn parse_uri(uri: &str) -> Result<Box<dyn Storable>> {
41
45
"file" => {
42
46
#[ cfg( feature = "storage-file" ) ]
43
47
{
44
- let path = std:: path:: Path :: new ( & uri [ idx + 3 .. ] ) ;
48
+ let path = std:: path:: Path :: new ( loc ) ;
45
49
let depot = super :: file:: FileStorage :: new ( path) ;
46
50
Ok ( Box :: new ( depot) )
47
51
}
@@ -53,7 +57,7 @@ fn parse_uri(uri: &str) -> Result<Box<dyn Storable>> {
53
57
"sqlite" => {
54
58
#[ cfg( feature = "storage-sqlite" ) ]
55
59
{
56
- let depot = super :: sqlite:: SqliteStorage :: new ( & uri [ idx + 3 .. ] ) ;
60
+ let depot = super :: sqlite:: SqliteStorage :: new ( loc ) ;
57
61
Ok ( Box :: new ( depot) )
58
62
}
59
63
#[ cfg( not( feature = "storage-sqlite" ) ) ]
@@ -64,7 +68,7 @@ fn parse_uri(uri: &str) -> Result<Box<dyn Storable>> {
64
68
"redis" => {
65
69
#[ cfg( feature = "storage-redis" ) ]
66
70
{
67
- let depot = super :: redis:: RedisStorage :: new ( & uri [ idx + 3 .. ] ) ?;
71
+ let depot = super :: redis:: RedisStorage :: new ( loc ) ?;
68
72
Ok ( Box :: new ( depot) )
69
73
}
70
74
#[ cfg( not( feature = "storage-redis" ) ) ]
@@ -75,7 +79,7 @@ fn parse_uri(uri: &str) -> Result<Box<dyn Storable>> {
75
79
"faulty" => {
76
80
#[ cfg( feature = "storage-faulty" ) ]
77
81
{
78
- let depot = super :: faulty:: FaultyStorage :: new ( & uri [ idx + 3 .. ] ) ;
82
+ let depot = super :: faulty:: FaultyStorage :: new ( loc ) ;
79
83
Ok ( Box :: new ( depot) )
80
84
}
81
85
#[ cfg( not( feature = "storage-faulty" ) ) ]
@@ -86,7 +90,7 @@ fn parse_uri(uri: &str) -> Result<Box<dyn Storable>> {
86
90
"zbox" => {
87
91
#[ cfg( feature = "storage-zbox" ) ]
88
92
{
89
- let depot = super :: zbox:: ZboxStorage :: new ( & uri [ idx + 3 .. ] ) ?;
93
+ let depot = super :: zbox:: ZboxStorage :: new ( loc ) ?;
90
94
Ok ( Box :: new ( depot) )
91
95
}
92
96
#[ cfg( not( feature = "storage-zbox" ) ) ]
0 commit comments