Skip to content

Assertion fails when passing C: as command line argument #367

Open
@rhysd

Description

@rhysd
Contributor

Repro

Run the following command in this repository:

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<std::process::ExitCode (*)(),tuple$<> >
             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

Path::new("C:").is_absolute()

returns false but

Path::new("C:\\foo").join("C:")

returns C:. This behavior causes the crash.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @rhysd

      Issue actions

        Assertion fails when passing `C:` as command line argument · Issue #367 · microsoft/edit