Skip to content

Commit

Permalink
Support bucket name with . when parsing GCS URL (#4991) (#4992)
Browse files Browse the repository at this point in the history
* Support bucket name with `.` when parsing GCS URL (#4991)

* Update test
  • Loading branch information
tustvold authored Oct 26, 2023
1 parent e78d140 commit 570c91e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
18 changes: 6 additions & 12 deletions object_store/src/gcp/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,8 @@ impl GoogleCloudStorageBuilder {
let parsed = Url::parse(url).context(UnableToParseUrlSnafu { url })?;
let host = parsed.host_str().context(UrlNotRecognisedSnafu { url })?;

let validate = |s: &str| match s.contains('.') {
true => Err(UrlNotRecognisedSnafu { url }.build()),
false => Ok(s.to_string()),
};

match parsed.scheme() {
"gs" => self.bucket_name = Some(validate(host)?),
"gs" => self.bucket_name = Some(host.to_string()),
scheme => return Err(UnknownUrlSchemeSnafu { scheme }.build().into()),
}
Ok(())
Expand Down Expand Up @@ -630,13 +625,12 @@ mod tests {
fn gcs_test_urls() {
let mut builder = GoogleCloudStorageBuilder::new();
builder.parse_url("gs://bucket/path").unwrap();
assert_eq!(builder.bucket_name, Some("bucket".to_string()));
assert_eq!(builder.bucket_name.as_deref(), Some("bucket"));

let err_cases = ["mailto://bucket/path", "gs://bucket.mydomain/path"];
let mut builder = GoogleCloudStorageBuilder::new();
for case in err_cases {
builder.parse_url(case).unwrap_err();
}
builder.parse_url("gs://bucket.mydomain/path").unwrap();
assert_eq!(builder.bucket_name.as_deref(), Some("bucket.mydomain"));

builder.parse_url("mailto://bucket/path").unwrap_err();
}

#[test]
Expand Down
4 changes: 4 additions & 0 deletions object_store/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ mod tests {
"gs://bucket/path",
(ObjectStoreScheme::GoogleCloudStorage, "path"),
),
(
"gs://test.example.com/path",
(ObjectStoreScheme::GoogleCloudStorage, "path"),
),
("http://mydomain/path", (ObjectStoreScheme::Http, "path")),
("https://mydomain/path", (ObjectStoreScheme::Http, "path")),
];
Expand Down

0 comments on commit 570c91e

Please sign in to comment.