microsoft / microsoft/edit

Assertion fails when passing `C:` as command line argument

Open Beginner friendly
#367 0 comments 2 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.