Skip to content

Commit

Permalink
Fix 838
Browse files Browse the repository at this point in the history
  • Loading branch information
valenting committed May 30, 2023
1 parent 206d378 commit 5432fd8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
7 changes: 6 additions & 1 deletion url/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ pub fn default_port(scheme: &str) -> Option<u16> {
}

#[derive(Clone)]
#[derive(Debug)]
pub struct Input<'i> {
chars: str::Chars<'i>,
}
Expand Down Expand Up @@ -1173,7 +1174,7 @@ impl<'a> Parser<'a> {
) -> Input<'i> {
// Relative path state
loop {
let segment_start = self.serialization.len();
let mut segment_start = self.serialization.len();
let mut ends_with_slash = false;
loop {
let input_before_c = input.clone();
Expand Down Expand Up @@ -1202,6 +1203,10 @@ impl<'a> Parser<'a> {
}
_ => {
self.check_url_code_point(c, &input);
if scheme_type.is_file() && is_normalized_windows_drive_letter(&self.serialization[path_start+1..]) {
self.serialization.push('/');
segment_start += 1;
}
if self.context == Context::PathSegmentSetter {
if scheme_type.is_special() {
self.serialization
Expand Down
23 changes: 23 additions & 0 deletions url/tests/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,3 +1262,26 @@ fn test_authority() {
"%C3%A0lex:%C3%A0lex@xn--lex-8ka.xn--p1ai.example.com"
);
}

#[test]
/// https://github.com/servo/rust-url/issues/838
fn test_file_with_drive() {
let s1 = "fIlE:p:?../";
let url = url::Url::parse(s1).unwrap();
assert_eq!(url.to_string(), "file:///p:?../");
assert_eq!(url.path(), "/p:");

let testcases = [
("a", "file:///p:/a"),
("", "file:///p:?../"),
("?x", "file:///p:?x"),
(".", "file:///p:/"),
("..", "file:///p:/"),
("../", "file:///p:/"),
];

for case in &testcases {
let url2 = url::Url::join(&url, case.0).unwrap();
assert_eq!(url2.to_string(), case.1);
}
}

0 comments on commit 5432fd8

Please sign in to comment.