Assertion fails when passing `C:` as command line argument
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 14.6k
- Forks
- 734
- Avg merge
- 8h 40m
- Merged PRs (30d)
- 4
Description
## Repro
Run the following command in this repository:
```sh
cargo run -- C:
```
## Expected result
Edit opens successfully with an untitled buffer.
## Actual result
Crashes with the following assertion error:
```
thread 'main' panicked at src\path.rs:12:5:
assertion failed: path.is_absolute()
stack backtrace:
0: std::panicking::begin_panic_handler
at /rustc/2805e1dc4c18ed4c84d161502c48da870c56f68a/library\std\src\panicking.rs:697
1: core::panicking::panic_fmt
at /rustc/2805e1dc4c18ed4c84d161502c48da870c56f68a/library\core\src\panicking.rs:75
2: core::panicking::panic
at /rustc/2805e1dc4c18ed4c84d161502c48da870c56f68a/library\core\src\panicking.rs:145
3: edit::path::normalize
at .\src\path.rs:12
4: edit::handle_args
at .\src\bin\edit\main.rs:253
5: edit::run
at .\src\bin\edit\main.rs:74
6: edit::main
at .\src\bin\edit\main.rs:56
7: core::ops::function::FnOnce::call_once >
at /rustc/2805e1dc4c18ed4c84d161502c48da870c56f68a\library\core\src\ops\function.rs:250
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
```
## Explanation
On Windows a drive letter path like `C:` is special. It is a relative path and it means the current working directory of the drive. If my understanding is correct, on Windows each drive has its current working directory.
This means
```rust
Path::new("C:").is_absolute()
```
returns `false` but
```rust
Path::new("C:\\foo").join("C:")
```
returns `C:`. This behavior causes the crash.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the failing assertion in src/path.rs:12 and trace how src/bin/edit/main.rs handles the C: argument around handle_args. Reproduce the issue with cargo run -- C: on Windows, then verify that the command opens successfully with an untitled buffer without panicking.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli, operating-systems
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 65/100