Url::parse does not encode backslash as %5C
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.6k
- Forks
- 406
- PR merge metrics
- No merged PRs in 30d
Description
Creating an URL with let mut url = "file:///foobar.com/foo\\bar".parse::<Url>().unwrap(); yields file:///foobar.com/foo/bar
I was expecting the backslash, for protocols like file://, http:// & https://, to be encoded as %5C or an error but instead it is converted to a forward slash. Maybe this is as per spec, i'm not sure, just confused 😅
Creating an URL with
let mut url = "file:///foobar.com/".parse::<Url>().unwrap();
url.path_segments_mut().unwrap().push("foo\\bar");
yields (the to me expected) file:///foobar.com//foo%5Cbar
Also parsing with Url::from_file_path("/path/to/folder/with\\backslash/in/folder/name") yields file:///path/to/folder/with\\backslash/in/folder/name and does not convert to forward slash.
I find all this confusing so i might be wrong but i expected that Url::from_file_path and Url::parse to be consistent. As it is now these two yield different results:
Url::from_file_path("/path/to/folder/with\\backslash/in/folder/name"); // yields file:// url with backslash present
Url::parse("file:///path/to/folder/with\\backslash/in/folder/name"); // yields file:// url with backslash converted to forward slash
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
Compare the behavior of Url::parse, path_segments_mut, and Url::from_file_path for backslashes in file, http, and https URLs, then check the relevant URL specification rules. Done means the intended behavior is established and the inconsistent parsing result is resolved or clearly documented with regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100