Skip to content

Commit 1a4e977

Browse files
committed
Getting there... hopefully.
1 parent 27225f1 commit 1a4e977

File tree

2 files changed

+22
-27
lines changed

2 files changed

+22
-27
lines changed

src/parser.rs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,16 +1028,17 @@ impl<'a> Parser<'a> {
10281028
let (maybe_c, remaining) = input.split_first();
10291029
// If url is special, then:
10301030
if scheme_type.is_special() {
1031-
// If c is U+005C (\), validation error.
1032-
if maybe_c == Some('\\') {
1033-
self.log_violation(SyntaxViolation::Backslash);
1034-
}
1035-
// If c is neither U+002F (/) nor U+005C (\), then decrease pointer by one.
1036-
if maybe_c == Some('/') || maybe_c == Some('\\') {
1037-
input = remaining;
1031+
if let Some(c) = maybe_c {
1032+
if c == '\\' {
1033+
// If c is U+005C (\), validation error.
1034+
self.log_violation(SyntaxViolation::Backslash);
1035+
}
1036+
// Set state to path state.
1037+
return self.parse_path(scheme_type, has_host, path_start, input);
1038+
} else {
1039+
// A special URL always has a non-empty path.
1040+
self.serialization.push('/');
10381041
}
1039-
// Set state to path state.
1040-
return self.parse_path(scheme_type, has_host, path_start, input);
10411042
} else if maybe_c == Some('?') {
10421043
// Otherwise, if state override is not given and c is U+003F (?),
10431044
// set url’s query to the empty string and state to query state.
@@ -1049,12 +1050,7 @@ impl<'a> Parser<'a> {
10491050
}
10501051
// Otherwise, if c is not the EOF code point:
10511052
if !remaining.is_empty() {
1052-
if maybe_c == Some('/') {
1053-
return self.parse_path(scheme_type, has_host, path_start, input);
1054-
} else {
1055-
// If c is not U+002F (/), then decrease pointer by one.
1056-
return self.parse_path(scheme_type, has_host, path_start, remaining);
1057-
}
1053+
return self.parse_path(scheme_type, has_host, path_start, input);
10581054
}
10591055
input
10601056
}
@@ -1127,9 +1123,6 @@ impl<'a> Parser<'a> {
11271123
path_start: usize,
11281124
mut input: Input<'i>,
11291125
) -> Input<'i> {
1130-
if !self.serialization.ends_with('/') && scheme_type.is_special() && !input.is_empty() {
1131-
self.serialization.push('/');
1132-
}
11331126
// Relative path state
11341127
loop {
11351128
let segment_start = self.serialization.len();
@@ -1151,7 +1144,7 @@ impl<'a> Parser<'a> {
11511144
&& scheme_type.is_special() =>
11521145
{
11531146
self.log_violation(SyntaxViolation::Backslash);
1154-
self.serialization.push(c);
1147+
self.serialization.push('/');
11551148
ends_with_slash = true;
11561149
break;
11571150
}
@@ -1175,18 +1168,26 @@ impl<'a> Parser<'a> {
11751168
}
11761169
}
11771170
}
1171+
11781172
match &self.serialization[segment_start..] {
1173+
// If buffer is a double-dot path segment, shorten url’s path,
1174+
// and then if neither c is U+002F (/), nor url is special and c is U+005C (\), append the empty string to url’s path.
11791175
".." | "%2e%2e" | "%2e%2E" | "%2E%2e" | "%2E%2E" | "%2e." | "%2E." | ".%2e"
11801176
| ".%2E" => {
11811177
debug_assert!(self.serialization.as_bytes()[segment_start - 1] == b'/');
11821178
self.serialization.truncate(segment_start - 1); // Truncate "/.."
11831179
self.pop_path(scheme_type, path_start);
1184-
if !self.serialization[path_start..].ends_with('/') {
1185-
self.serialization.push('/')
1180+
if ends_with_slash && !self.serialization.ends_with("/") {
1181+
self.serialization.push('/');
11861182
}
11871183
}
1184+
// Otherwise, if buffer is a single-dot path segment and if neither c is U+002F (/),
1185+
// nor url is special and c is U+005C (\), append the empty string to url’s path.
11881186
"." | "%2e" | "%2E" => {
11891187
self.serialization.truncate(segment_start);
1188+
if ends_with_slash && !self.serialization.ends_with("/") {
1189+
self.serialization.push('/');
1190+
}
11901191
}
11911192
_ => {
11921193
if scheme_type.is_file()
@@ -1201,9 +1202,6 @@ impl<'a> Parser<'a> {
12011202
*has_host = false; // FIXME account for this in callers
12021203
}
12031204
}
1204-
if ends_with_slash {
1205-
self.serialization.push('/')
1206-
}
12071205
}
12081206
}
12091207
if !ends_with_slash {

src/quirks.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ pub fn host(url: &Url) -> &str {
9999

100100
/// Setter for https://url.spec.whatwg.org/#dom-url-host
101101
pub fn set_host(url: &mut Url, new_host: &str) -> Result<(), ()> {
102-
if url.cannot_be_a_base() {
103-
return Err(());
104-
}
105102
let host;
106103
let opt_port;
107104
{

0 commit comments

Comments
 (0)