url.to_file_path() fails for unix:///C:/windows/path
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.6k
- Forks
- 406
- PR merge metrics
- No merged PRs in 30d
Description
Windows now supports Unix domain sockets.
If I parse a unix:// URL with a Windows path, then try to get the path back, I get an error:
extern crate url;
use url::Url;
fn main() {
let path = "C:\\path\\to\\file";
let file_url = "file:///C:/path/to/file";
let unix_url = "unix:///C:/path/to/file";
let mut one = Url::from_file_path(path).unwrap();
let _ = one.set_scheme("unix").unwrap();
assert_eq!(one.to_file_path().unwrap().as_os_str(), path);
let two = Url::parse(file_url).unwrap();
assert_eq!(two.to_file_path().unwrap().as_os_str(), path);
let three = Url::parse(unix_url).unwrap();
assert_eq!(three.to_file_path().unwrap().as_os_str(), path); // <-- panic!
}
PS C:\projects\rs-url-roundtrip> target\debug\rs-url-roundtrip.exe
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ()', libcore\result.rs:945:5
As the code shows, the from_file_path/to_file_path round trip works, as does the parse/to_file_path round trip for a file:// URL. It would be great if the parse/to_file_path worked for unix:// as well.
Contributor guide
No contributing guide indexed for this repository
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 by locating the implementation of Url::to_file_path and the existing file-URL path conversion tests. Reproduce the Windows unix:///C:/path/to/file case from the issue, then add coverage showing the expected path conversion and run the relevant test suite to confirm the regression is fixed.
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