apache / apache/opendal

bug: fail to read files with trailing whitespaces

Open Beginner friendly
#6,577 5 comments 1 reaction 0 assignees View on GitHub
bug releases-note/fix services/fs
Dominant language
Rust
Stars
5.4k
Forks
825
Avg merge
1d 14m
Merged PRs (30d)
127

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 {
self.read_options(path, options::ReadOptions::default())
.await
}

pub async fn read_options(&self, path: &str, opts: options::ReadOptions) -> Result {
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::>()
.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.

Contributor guide

Open the contributing guide

Research direction

Start with normalize_path and its use from read() and read_options(), as shown in the issue. Reproduce the case using a filename ending in a space, then verify that reading it succeeds while the existing slash normalization remains intact. Done means the trailing-space filename can be read without the path being trimmed.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.