Skip to content

Commit b908f7f

Browse files
committed
Merge branch 'master' into no_std
2 parents af1d5d5 + a3e07c7 commit b908f7f

File tree

8 files changed

+61
-15
lines changed

8 files changed

+61
-15
lines changed

data-url/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "data-url"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
authors = ["Simon Sapin <simon.sapin@exyr.org>"]
55
description = "Processing of data: URL according to WHATWG’s Fetch Standard"
66
categories = ["no_std"]

form_urlencoded/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "form_urlencoded"
3-
version = "1.1.0"
3+
version = "1.2.0"
44
authors = ["The rust-url developers"]
55
description = "Parser and serializer for the application/x-www-form-urlencoded syntax, as used by HTML forms."
66
categories = ["no_std"]
@@ -18,4 +18,4 @@ std = ["alloc", "percent-encoding/std"]
1818
alloc = ["percent-encoding/alloc"]
1919

2020
[dependencies]
21-
percent-encoding = { version = "2.2.0", default-features = false, path = "../percent_encoding" }
21+
percent-encoding = { version = "2.3.0", default-features = false, path = "../percent_encoding" }

idna/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "idna"
3-
version = "0.3.0"
3+
version = "0.4.0"
44
authors = ["The rust-url developers"]
55
description = "IDNA (Internationalizing Domain Names in Applications) and Punycode."
66
categories = ["no_std"]

percent_encoding/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "percent-encoding"
3-
version = "2.2.0"
3+
version = "2.3.0"
44
authors = ["The rust-url developers"]
55
description = "Percent encoding and decoding"
66
categories = ["no_std"]

url/Cargo.toml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
name = "url"
44
# When updating version, also modify html_root_url in the lib.rs
5-
version = "2.3.1"
5+
version = "2.4.0"
66
authors = ["The rust-url developers"]
77

88
description = "URL library for Rust, based on the WHATWG URL Standard"
@@ -28,11 +28,10 @@ debugger_test = "0.1"
2828
debugger_test_parser = "0.1"
2929

3030
[dependencies]
31-
form_urlencoded = { version = "1.1.0", path = "../form_urlencoded", default-features = false, features = ["alloc"] }
32-
idna = { version = "0.3.0", path = "../idna", default-features = false, features = ["alloc"] }
33-
percent-encoding = { version = "2.2.0", path = "../percent_encoding", default-features = false, features = ["alloc"] }
34-
data-url = { version = "0.2.0", path = "../data-url", default-features = false, features = ["alloc"] }
35-
serde = {version = "1.0", optional = true, default-features = false, features = ["alloc", "derive"]}
31+
form_urlencoded = { version = "1.2.0", path = "../form_urlencoded", default-features = false, features = ["alloc"] }
32+
idna = { version = "0.4.0", path = "../idna", default-features = false, features = ["alloc"] }
33+
percent-encoding = { version = "2.3.0", path = "../percent_encoding", default-features = false, features = ["alloc"] }
34+
serde = {version = "1.0", optional = true, features = ["derive"]}
3635
no-std-net = { version = "0.6.0", default-features = false, optional = true }
3736

3837
[features]

url/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ url = { version = "2", features = ["serde"] }
122122
*/
123123

124124
#![no_std]
125-
#![doc(html_root_url = "https://docs.rs/url/2.3.1")]
125+
#![doc(html_root_url = "https://docs.rs/url/2.4.0")]
126126
#![cfg_attr(
127127
feature = "debugger_visualizer",
128128
feature(debugger_visualizer),

url/src/parser.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ pub fn default_port(scheme: &str) -> Option<u16> {
182182
}
183183
}
184184

185-
#[derive(Clone)]
185+
#[derive(Clone, Debug)]
186186
pub struct Input<'i> {
187187
chars: str::Chars<'i>,
188188
}
@@ -1177,7 +1177,7 @@ impl<'a> Parser<'a> {
11771177
) -> Input<'i> {
11781178
// Relative path state
11791179
loop {
1180-
let segment_start = self.serialization.len();
1180+
let mut segment_start = self.serialization.len();
11811181
let mut ends_with_slash = false;
11821182
loop {
11831183
let input_before_c = input.clone();
@@ -1206,6 +1206,14 @@ impl<'a> Parser<'a> {
12061206
}
12071207
_ => {
12081208
self.check_url_code_point(c, &input);
1209+
if scheme_type.is_file()
1210+
&& is_normalized_windows_drive_letter(
1211+
&self.serialization[path_start + 1..],
1212+
)
1213+
{
1214+
self.serialization.push('/');
1215+
segment_start += 1;
1216+
}
12091217
if self.context == Context::PathSegmentSetter {
12101218
if scheme_type.is_special() {
12111219
self.serialization
@@ -1253,7 +1261,10 @@ impl<'a> Parser<'a> {
12531261
}
12541262
_ => {
12551263
// If url’s scheme is "file", url’s path is empty, and buffer is a Windows drive letter, then
1256-
if scheme_type.is_file() && is_windows_drive_letter(segment_before_slash) {
1264+
if scheme_type.is_file()
1265+
&& segment_start == path_start + 1
1266+
&& is_windows_drive_letter(segment_before_slash)
1267+
{
12571268
// Replace the second code point in buffer with U+003A (:).
12581269
if let Some(c) = segment_before_slash.chars().next() {
12591270
self.serialization.truncate(segment_start);

url/tests/unit.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,3 +1327,39 @@ fn test_authority() {
13271327
"%C3%A0lex:%C3%A0lex@xn--lex-8ka.xn--p1ai.example.com"
13281328
);
13291329
}
1330+
1331+
#[test]
1332+
/// https://github.com/servo/rust-url/issues/838
1333+
fn test_file_with_drive() {
1334+
let s1 = "fIlE:p:?../";
1335+
let url = url::Url::parse(s1).unwrap();
1336+
assert_eq!(url.to_string(), "file:///p:?../");
1337+
assert_eq!(url.path(), "/p:");
1338+
1339+
let testcases = [
1340+
("a", "file:///p:/a"),
1341+
("", "file:///p:?../"),
1342+
("?x", "file:///p:?x"),
1343+
(".", "file:///p:/"),
1344+
("..", "file:///p:/"),
1345+
("../", "file:///p:/"),
1346+
];
1347+
1348+
for case in &testcases {
1349+
let url2 = url::Url::join(&url, case.0).unwrap();
1350+
assert_eq!(url2.to_string(), case.1);
1351+
}
1352+
}
1353+
1354+
#[test]
1355+
/// Similar to test_file_with_drive, but with a path
1356+
/// that could be confused for a drive.
1357+
fn test_file_with_drive_and_path() {
1358+
let s1 = "fIlE:p:/x|?../";
1359+
let url = url::Url::parse(s1).unwrap();
1360+
assert_eq!(url.to_string(), "file:///p:/x|?../");
1361+
assert_eq!(url.path(), "/p:/x|");
1362+
let s2 = "a";
1363+
let url2 = url::Url::join(&url, s2).unwrap();
1364+
assert_eq!(url2.to_string(), "file:///p:/a");
1365+
}

0 commit comments

Comments
 (0)