-
Notifications
You must be signed in to change notification settings - Fork 646
Open
Labels
bugSomething isn't workingSomething isn't workingreleases-note/fixThe PR fixes a bug or has a title that begins with "fix"The PR fixes a bug or has a title that begins with "fix"services/fs
Description
Describe the bug
When using the read() method in opendal 0.54.0
opendal fail to read the content from the file
Steps to Reproduce
Create a file named "file with trailing white space " with some content in it
Use the read method to read the file content. It will fail with Error.
Expected Behavior
I expect to be able to read the content of a file even if the file name ends with a white space
Additional Context
The calls in this snippet shows that the normalize_path in deed trims the string from any leading or trailing white space.
pub async fn read(&self, path: &str) -> Result<Buffer> {
self.read_options(path, options::ReadOptions::default())
.await
}
pub async fn read_options(&self, path: &str, opts: options::ReadOptions) -> Result<Buffer> {
let path = normalize_path(path);
Self::read_inner(self.inner().clone(), path, opts).await
}
pub fn normalize_path(path: &str) -> String {
// - all whitespace has been trimmed.
// - all leading `/` has been trimmed.
let path = path.trim().trim_start_matches('/');
// Fast line for empty path.
if path.is_empty() {
return "/".to_string();
}
let has_trailing = path.ends_with('/');
let mut p = path
.split('/')
.filter(|v| !v.is_empty())
.collect::<Vec<&str>>()
.join("/");
// Append trailing back if input path is endswith `/`.
if has_trailing {
p.push('/');
}
p
}
Are you willing to submit a PR to fix this bug?
- Yes, I would like to submit a PR.
dosubot
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingreleases-note/fixThe PR fixes a bug or has a title that begins with "fix"The PR fixes a bug or has a title that begins with "fix"services/fs