services::Fs shouldn't trim path names with spaces when listing
- Dominant language
- Rust
- Stars
- 5.4k
- Forks
- 825
- Avg merge
- 1d 14m
- Merged PRs (30d)
- 127
Description
If a folder contains an empty space at the end, listing seems to trim making it an invalid path.
Create a new empty project `cargo new opendal-space-bug`.
Cargo.toml
```toml
[package]
name = "opendal-space-bug"
version = "0.1.0"
edition = "2021"
[dependencies]
futures-util = "0.3.30"
opendal = { version = "0.46.0", features = ["services-fs"] }
tokio = { version = "1.37.0", features = ["full"] }
```
main.rs
```rust
use futures_util::StreamExt;
use opendal::{services, Operator};
#[tokio::main]
async fn main() {
let mut builder = services::Fs::default();
builder.root("/Users/prabirshrestha/code/tmp/opendal-space-bug");
let op = Operator::new(builder).unwrap().finish();
let mut ds = op.lister_with("/").recursive(false).await.unwrap();
while let Some(item) = ds.next().await {
let item = item.unwrap();
dbg!(item.path());
}
}
```
`cargo run` will work as expected.
```
/Users/prabirshrestha/code/tmp/opendal-space-bug$ cargo run
Compiling opendal-space-bug v0.1.0 (/Users/prabirshrestha/code/tmp/opendal-space-bug)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.25s
Running `target/debug/opendal-space-bug`
[src/main.rs:14:9] item.path() = "Cargo.toml"
[src/main.rs:14:9] item.path() = "target/"
[src/main.rs:14:9] item.path() = "Cargo.lock"
[src/main.rs:14:9] item.path() = ".gitignore"
[src/main.rs:14:9] item.path() = ".git/"
[src/main.rs:14:9] item.path() = "src/"
```
Now create a directory with trailing slash at the end. `mkdir "hello "`.
Run the program again. Notice that it is `hello/` instead of `hello /`.
```
/Users/prabirshrestha/code/tmp/opendal-space-bug$ cargo run
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s
Running `target/debug/opendal-space-bug`
[src/main.rs:14:9] item.path() = "Cargo.toml"
[src/main.rs:14:9] item.path() = "target/"
[src/main.rs:14:9] item.path() = "hello/"
[src/main.rs:14:9] item.path() = "Cargo.lock"
[src/main.rs:14:9] item.path() = ".gitignore"
[src/main.rs:14:9] item.path() = ".git/"
[src/main.rs:14:9] item.path() = "src/"
```
Same seems to happen with names that starts with space. Try with `mkdir " world"`. It shows "world/" instead of " world/".
```
/Users/prabirshrestha/code/tmp/opendal-space-bug$ cargo run
Compiling opendal-space-bug v0.1.0 (/Users/prabirshrestha/code/tmp/opendal-space-bug)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.22s
Running `target/debug/opendal-space-bug`
[src/main.rs:14:9] item.path() = "Cargo.toml"
[src/main.rs:14:9] item.path() = "target/"
[src/main.rs:14:9] item.path() = "hello/"
[src/main.rs:14:9] item.path() = "Cargo.lock"
[src/main.rs:14:9] item.path() = "world/"
[src/main.rs:14:9] item.path() = ".gitignore"
[src/main.rs:14:9] item.path() = ".git/"
[src/main.rs:14:9] item.path() = "src/"
```
Contributor guide
Research direction
Reproduce the issue with the Cargo.toml and main.rs example, using services::Fs and directories with leading or trailing spaces. Start by tracing the Fs listing implementation invoked by lister_with("/") and inspect how returned names are normalized. Done means cargo run reports directory paths with their original spaces preserved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100