Skip to content

Commit 5432fd8

Browse files
committed
Fix 838
1 parent 206d378 commit 5432fd8

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

url/src/parser.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ pub fn default_port(scheme: &str) -> Option<u16> {
179179
}
180180

181181
#[derive(Clone)]
182+
#[derive(Debug)]
182183
pub struct Input<'i> {
183184
chars: str::Chars<'i>,
184185
}
@@ -1173,7 +1174,7 @@ impl<'a> Parser<'a> {
11731174
) -> Input<'i> {
11741175
// Relative path state
11751176
loop {
1176-
let segment_start = self.serialization.len();
1177+
let mut segment_start = self.serialization.len();
11771178
let mut ends_with_slash = false;
11781179
loop {
11791180
let input_before_c = input.clone();
@@ -1202,6 +1203,10 @@ impl<'a> Parser<'a> {
12021203
}
12031204
_ => {
12041205
self.check_url_code_point(c, &input);
1206+
if scheme_type.is_file() && is_normalized_windows_drive_letter(&self.serialization[path_start+1..]) {
1207+
self.serialization.push('/');
1208+
segment_start += 1;
1209+
}
12051210
if self.context == Context::PathSegmentSetter {
12061211
if scheme_type.is_special() {
12071212
self.serialization

url/tests/unit.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,3 +1262,26 @@ fn test_authority() {
12621262
"%C3%A0lex:%C3%A0lex@xn--lex-8ka.xn--p1ai.example.com"
12631263
);
12641264
}
1265+
1266+
#[test]
1267+
/// https://github.com/servo/rust-url/issues/838
1268+
fn test_file_with_drive() {
1269+
let s1 = "fIlE:p:?../";
1270+
let url = url::Url::parse(s1).unwrap();
1271+
assert_eq!(url.to_string(), "file:///p:?../");
1272+
assert_eq!(url.path(), "/p:");
1273+
1274+
let testcases = [
1275+
("a", "file:///p:/a"),
1276+
("", "file:///p:?../"),
1277+
("?x", "file:///p:?x"),
1278+
(".", "file:///p:/"),
1279+
("..", "file:///p:/"),
1280+
("../", "file:///p:/"),
1281+
];
1282+
1283+
for case in &testcases {
1284+
let url2 = url::Url::join(&url, case.0).unwrap();
1285+
assert_eq!(url2.to_string(), case.1);
1286+
}
1287+
}

0 commit comments

Comments
 (0)