Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

windows: to_file_path() panics for certain URLs created by from_file_path() #505

Open
piscisaureus opened this issue Jul 8, 2019 · 3 comments

Comments

@piscisaureus
Copy link

use std::path::PathBuf;
use url::Url;

fn main() {
    let p = PathBuf::from("c:///");
    let u = Url::from_file_path(p).unwrap();
    println!("url: {:?}", u);
    let r = u.to_file_path();  // <-- Panic happens here
    println!("result: {:?}", r);
}

output:

url: "file:///C:"
thread 'main' panicked at 'to_file_path() failed to produce an absolute Path', C:\Users\BertBelder\.cargo\registry\src\github.heygears.com-1ecc6299db9ec823\url-1.7.2\src\lib.rs:2415:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
error: process didn't exit successfully: `target\debug\urlt.exe` (exit code: 101)
@opilar
Copy link

opilar commented Jul 19, 2019

Stack:

url: "file:///C:"
thread 'main' panicked at 'to_file_path() failed to produce an absolute Path', src\lib.rs:2461:5
stack backtrace:
   0: std::sys::windows::backtrace::set_frames
             at /rustc/a53f9df32fbb0b5f4382caaad8f1a46f36ea887c\/src\libstd\sys\windows\backtrace\mod.rs:95
   1: std::sys::windows::backtrace::unwind_backtrace
             at /rustc/a53f9df32fbb0b5f4382caaad8f1a46f36ea887c\/src\libstd\sys\windows\backtrace\mod.rs:82
   2: std::sys_common::backtrace::_print
             at /rustc/a53f9df32fbb0b5f4382caaad8f1a46f36ea887c\/src\libstd\sys_common\backtrace.rs:71
   3: std::sys_common::backtrace::print
             at /rustc/a53f9df32fbb0b5f4382caaad8f1a46f36ea887c\/src\libstd\sys_common\backtrace.rs:59
   4: std::panicking::default_hook::{{closure}}
             at /rustc/a53f9df32fbb0b5f4382caaad8f1a46f36ea887c\/src\libstd\panicking.rs:197
   5: std::panicking::default_hook
             at /rustc/a53f9df32fbb0b5f4382caaad8f1a46f36ea887c\/src\libstd\panicking.rs:211
   6: std::panicking::rust_panic_with_hook
             at /rustc/a53f9df32fbb0b5f4382caaad8f1a46f36ea887c\/src\libstd\panicking.rs:474
   7: std::panicking::begin_panic<str*>
             at /rustc/a53f9df32fbb0b5f4382caaad8f1a46f36ea887c\src\libstd\panicking.rs:408
   8: url::file_url_segments_to_pathbuf_windows
             at .\src\lib.rs:2461
   9: url::file_url_segments_to_pathbuf
             at .\src\lib.rs:2412
  10: url::Url::to_file_path
             at .\src\lib.rs:2144
  11: url::main
             at .\src\main.rs:10
  12: std::rt::lang_start::{{closure}}<()>
             at /rustc/a53f9df32fbb0b5f4382caaad8f1a46f36ea887c\src\libstd\rt.rs:64
  13: std::rt::lang_start_internal::{{closure}}
             at /rustc/a53f9df32fbb0b5f4382caaad8f1a46f36ea887c\/src\libstd\rt.rs:49
  14: std::panicking::try::do_call<closure,i32>
             at /rustc/a53f9df32fbb0b5f4382caaad8f1a46f36ea887c\/src\libstd\panicking.rs:293
  15: panic_unwind::__rust_maybe_catch_panic
             at /rustc/a53f9df32fbb0b5f4382caaad8f1a46f36ea887c\/src\libpanic_unwind\lib.rs:85
  16: std::panicking::try
             at /rustc/a53f9df32fbb0b5f4382caaad8f1a46f36ea887c\/src\libstd\panicking.rs:272
  17: std::panic::catch_unwind
             at /rustc/a53f9df32fbb0b5f4382caaad8f1a46f36ea887c\/src\libstd\panic.rs:394
  18: std::rt::lang_start_internal
             at /rustc/a53f9df32fbb0b5f4382caaad8f1a46f36ea887c\/src\libstd\rt.rs:48
  19: std::rt::lang_start<()>
             at /rustc/a53f9df32fbb0b5f4382caaad8f1a46f36ea887c\src\libstd\rt.rs:64
  20: main
  21: invoke_main
             at d:\agent\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  22: __scrt_common_main_seh
             at d:\agent\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
  23: BaseThreadInitThunk
  24: RtlUserThreadStart

@o0Ignition0o
Copy link
Contributor

Ok it seems to occur when the path only has a prefix (no segments).
I think I have a working patch, but I would love us to have a way to automatically test it and make sure It won't happen again (#102 is part of that effort).

@dsherret
Copy link
Contributor

dsherret commented Oct 9, 2024

Another example: file://asdf

dsherret added a commit to denoland/deno that referenced this issue Dec 6, 2024
I tried adding a test, but it's not possible due to a debug assertion in
the url crate (servo/rust-url#505)

Closes #27258
bartlomieju pushed a commit to denoland/deno that referenced this issue Dec 11, 2024
I tried adding a test, but it's not possible due to a debug assertion in
the url crate (servo/rust-url#505)

Closes #27258
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants