Skip to content

Commit 8adaede

Browse files
committed
Getting there... hopefully.
1 parent cd5f0ae commit 8adaede

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
@@ -1046,16 +1046,17 @@ impl<'a> Parser<'a> {
10461046
let (maybe_c, remaining) = input.split_first();
10471047
// If url is special, then:
10481048
if scheme_type.is_special() {
1049-
// If c is U+005C (\), validation error.
1050-
if maybe_c == Some('\\') {
1051-
self.log_violation(SyntaxViolation::Backslash);
1052-
}
1053-
// If c is neither U+002F (/) nor U+005C (\), then decrease pointer by one.
1054-
if maybe_c == Some('/') || maybe_c == Some('\\') {
1055-
input = remaining;
1049+
if let Some(c) = maybe_c {
1050+
if c == '\\' {
1051+
// If c is U+005C (\), validation error.
1052+
self.log_violation(SyntaxViolation::Backslash);
1053+
}
1054+
// Set state to path state.
1055+
return self.parse_path(scheme_type, has_host, path_start, input);
1056+
} else {
1057+
// A special URL always has a non-empty path.
1058+
self.serialization.push('/');
10561059
}
1057-
// Set state to path state.
1058-
return self.parse_path(scheme_type, has_host, path_start, input);
10591060
} else if maybe_c == Some('?') {
10601061
// Otherwise, if state override is not given and c is U+003F (?),
10611062
// set url’s query to the empty string and state to query state.
@@ -1067,12 +1068,7 @@ impl<'a> Parser<'a> {
10671068
}
10681069
// Otherwise, if c is not the EOF code point:
10691070
if !remaining.is_empty() {
1070-
if maybe_c == Some('/') {
1071-
return self.parse_path(scheme_type, has_host, path_start, input);
1072-
} else {
1073-
// If c is not U+002F (/), then decrease pointer by one.
1074-
return self.parse_path(scheme_type, has_host, path_start, remaining);
1075-
}
1071+
return self.parse_path(scheme_type, has_host, path_start, input);
10761072
}
10771073
input
10781074
}
@@ -1145,9 +1141,6 @@ impl<'a> Parser<'a> {
11451141
path_start: usize,
11461142
mut input: Input<'i>,
11471143
) -> Input<'i> {
1148-
if !self.serialization.ends_with('/') && scheme_type.is_special() && !input.is_empty() {
1149-
self.serialization.push('/');
1150-
}
11511144
// Relative path state
11521145
loop {
11531146
let segment_start = self.serialization.len();
@@ -1169,7 +1162,7 @@ impl<'a> Parser<'a> {
11691162
&& scheme_type.is_special() =>
11701163
{
11711164
self.log_violation(SyntaxViolation::Backslash);
1172-
self.serialization.push(c);
1165+
self.serialization.push('/');
11731166
ends_with_slash = true;
11741167
break;
11751168
}
@@ -1193,18 +1186,26 @@ impl<'a> Parser<'a> {
11931186
}
11941187
}
11951188
}
1189+
11961190
match &self.serialization[segment_start..] {
1191+
// If buffer is a double-dot path segment, shorten url’s path,
1192+
// 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.
11971193
".." | "%2e%2e" | "%2e%2E" | "%2E%2e" | "%2E%2E" | "%2e." | "%2E." | ".%2e"
11981194
| ".%2E" => {
11991195
debug_assert!(self.serialization.as_bytes()[segment_start - 1] == b'/');
12001196
self.serialization.truncate(segment_start - 1); // Truncate "/.."
12011197
self.pop_path(scheme_type, path_start);
1202-
if !self.serialization[path_start..].ends_with('/') {
1203-
self.serialization.push('/')
1198+
if ends_with_slash && !self.serialization.ends_with("/") {
1199+
self.serialization.push('/');
12041200
}
12051201
}
1202+
// Otherwise, if buffer is a single-dot path segment and if neither c is U+002F (/),
1203+
// nor url is special and c is U+005C (\), append the empty string to url’s path.
12061204
"." | "%2e" | "%2E" => {
12071205
self.serialization.truncate(segment_start);
1206+
if ends_with_slash && !self.serialization.ends_with("/") {
1207+
self.serialization.push('/');
1208+
}
12081209
}
12091210
_ => {
12101211
if scheme_type.is_file()
@@ -1219,9 +1220,6 @@ impl<'a> Parser<'a> {
12191220
*has_host = false; // FIXME account for this in callers
12201221
}
12211222
}
1222-
if ends_with_slash {
1223-
self.serialization.push('/')
1224-
}
12251223
}
12261224
}
12271225
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)