Skip to content

Commit f422dce

Browse files
authored
Fix azure path parsing (apache#399)
1 parent 70cd178 commit f422dce

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

src/parse.rs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl ObjectStoreScheme {
9292
/// assert_eq!(scheme, ObjectStoreScheme::Local);
9393
/// assert_eq!(path.as_ref(), "path/to/my/file");
9494
///
95-
/// let url: Url = "https://blob.core.windows.net/path/to/my/file".parse().unwrap();
95+
/// let url: Url = "https://blob.core.windows.net/container/path/to/my/file".parse().unwrap();
9696
/// let (scheme, path) = ObjectStoreScheme::parse(&url).unwrap();
9797
/// assert_eq!(scheme, ObjectStoreScheme::MicrosoftAzure);
9898
/// assert_eq!(path.as_ref(), "path/to/my/file");
@@ -110,17 +110,16 @@ impl ObjectStoreScheme {
110110
("memory", None) => (Self::Memory, url.path()),
111111
("s3" | "s3a", Some(_)) => (Self::AmazonS3, url.path()),
112112
("gs", Some(_)) => (Self::GoogleCloudStorage, url.path()),
113-
("az" | "adl" | "azure" | "abfs" | "abfss", Some(_)) => {
114-
(Self::MicrosoftAzure, url.path())
115-
}
113+
("az", Some(_)) => (Self::MicrosoftAzure, strip_bucket().unwrap_or_default()),
114+
("adl" | "azure" | "abfs" | "abfss", Some(_)) => (Self::MicrosoftAzure, url.path()),
116115
("http", Some(_)) => (Self::Http, url.path()),
117116
("https", Some(host)) => {
118117
if host.ends_with("dfs.core.windows.net")
119118
|| host.ends_with("blob.core.windows.net")
120119
|| host.ends_with("dfs.fabric.microsoft.com")
121120
|| host.ends_with("blob.fabric.microsoft.com")
122121
{
123-
(Self::MicrosoftAzure, url.path())
122+
(Self::MicrosoftAzure, strip_bucket().unwrap_or_default())
124123
} else if host.ends_with("amazonaws.com") {
125124
match host.starts_with("s3") {
126125
true => (Self::AmazonS3, strip_bucket().unwrap_or_default()),
@@ -286,10 +285,26 @@ mod tests {
286285
"https://account.dfs.core.windows.net",
287286
(ObjectStoreScheme::MicrosoftAzure, ""),
288287
),
288+
(
289+
"https://account.dfs.core.windows.net/container/path",
290+
(ObjectStoreScheme::MicrosoftAzure, "path"),
291+
),
289292
(
290293
"https://account.blob.core.windows.net",
291294
(ObjectStoreScheme::MicrosoftAzure, ""),
292295
),
296+
(
297+
"https://account.blob.core.windows.net/container/path",
298+
(ObjectStoreScheme::MicrosoftAzure, "path"),
299+
),
300+
(
301+
"az://account/container",
302+
(ObjectStoreScheme::MicrosoftAzure, ""),
303+
),
304+
(
305+
"az://account/container/path",
306+
(ObjectStoreScheme::MicrosoftAzure, "path"),
307+
),
293308
(
294309
"gs://bucket/path",
295310
(ObjectStoreScheme::GoogleCloudStorage, "path"),
@@ -335,15 +350,23 @@ mod tests {
335350
),
336351
(
337352
"https://account.dfs.fabric.microsoft.com/container",
338-
(ObjectStoreScheme::MicrosoftAzure, "container"),
353+
(ObjectStoreScheme::MicrosoftAzure, ""),
354+
),
355+
(
356+
"https://account.dfs.fabric.microsoft.com/container/path",
357+
(ObjectStoreScheme::MicrosoftAzure, "path"),
339358
),
340359
(
341360
"https://account.blob.fabric.microsoft.com/",
342361
(ObjectStoreScheme::MicrosoftAzure, ""),
343362
),
344363
(
345364
"https://account.blob.fabric.microsoft.com/container",
346-
(ObjectStoreScheme::MicrosoftAzure, "container"),
365+
(ObjectStoreScheme::MicrosoftAzure, ""),
366+
),
367+
(
368+
"https://account.blob.fabric.microsoft.com/container/path",
369+
(ObjectStoreScheme::MicrosoftAzure, "path"),
347370
),
348371
];
349372

0 commit comments

Comments
 (0)