Skip to content

Commit

Permalink
Decode URL paths (#5017) (#5018)
Browse files Browse the repository at this point in the history
  • Loading branch information
tustvold authored Nov 1, 2023
1 parent 94fe6bb commit ec788e1
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions object_store/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ impl ObjectStoreScheme {
_ => return Err(Error::Unrecognised { url: url.clone() }),
};

let path = Path::parse(path)?;
Ok((scheme, path))
Ok((scheme, Path::from_url_path(path)?))
}
}

Expand Down Expand Up @@ -240,6 +239,18 @@ mod tests {
),
("http://mydomain/path", (ObjectStoreScheme::Http, "path")),
("https://mydomain/path", (ObjectStoreScheme::Http, "path")),
(
"s3://bucket/foo%20bar",
(ObjectStoreScheme::AmazonS3, "foo bar"),
),
(
"https://foo/bar%20baz",
(ObjectStoreScheme::Http, "bar baz"),
),
(
"file:///bar%252Efoo",
(ObjectStoreScheme::Local, "bar%2Efoo"),
),
];

for (s, (expected_scheme, expected_path)) in cases {
Expand All @@ -260,4 +271,12 @@ mod tests {
assert!(ObjectStoreScheme::parse(&url).is_err());
}
}

#[test]
fn test_url_spaces() {
let url = Url::parse("file:///my file with spaces").unwrap();
assert_eq!(url.path(), "/my%20file%20with%20spaces");
let (_, path) = parse_url(&url).unwrap();
assert_eq!(path.as_ref(), "my file with spaces");
}
}

0 comments on commit ec788e1

Please sign in to comment.