Skip to content

Commit 2352f3e

Browse files
authored
Fix ListingTableUrl to decode percent (#3750)
* fix: ListingTabUrl prefix decoding * chore: remove waste change * fix: use from instead of parse * test: add test cases for prefix * chore: cargo fmt
1 parent ac1631a commit 2352f3e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

datafusion/core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ ordered-float = "3.0"
8080
parking_lot = "0.12"
8181
parquet = { version = "24.0.0", features = ["arrow", "async"] }
8282
paste = "^1.0"
83+
percent-encoding = "2.2.0"
8384
pin-project-lite = "^0.2.7"
8485
pyo3 = { version = "0.17.1", optional = true }
8586
rand = "0.8"

datafusion/core/src/datasource/listing/url.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use glob::Pattern;
2323
use itertools::Itertools;
2424
use object_store::path::Path;
2525
use object_store::{ObjectMeta, ObjectStore};
26+
use percent_encoding;
2627
use url::Url;
2728

2829
/// A parsed URL identifying files for a listing table, see [`ListingTableUrl::parse`]
@@ -108,7 +109,9 @@ impl ListingTableUrl {
108109

109110
/// Creates a new [`ListingTableUrl`] from a url and optional glob expression
110111
fn new(url: Url, glob: Option<Pattern>) -> Self {
111-
let prefix = Path::parse(url.path()).expect("should be URL safe");
112+
let decoded_path =
113+
percent_encoding::percent_decode_str(url.path()).decode_utf8_lossy();
114+
let prefix = Path::from(decoded_path.as_ref());
112115
Self { url, prefix, glob }
113116
}
114117

@@ -246,6 +249,15 @@ mod tests {
246249
let url = ListingTableUrl::parse("file:///foo").unwrap();
247250
let child = Path::parse("/foob/bar").unwrap();
248251
assert!(url.strip_prefix(&child).is_none());
252+
253+
let url = ListingTableUrl::parse("file:///foo/ bar").unwrap();
254+
assert_eq!(url.prefix.as_ref(), "foo/ bar");
255+
256+
let url = ListingTableUrl::parse("file:///foo/bar?").unwrap();
257+
assert_eq!(url.prefix.as_ref(), "foo/bar");
258+
259+
let url = ListingTableUrl::parse("file:///foo/😺").unwrap();
260+
assert_eq!(url.prefix.as_ref(), "foo/%F0%9F%98%BA");
249261
}
250262

251263
#[test]

0 commit comments

Comments
 (0)