Skip to content

Commit 15441ec

Browse files
committed
UTF-8 percent encoding tests. Also fixed prefix slash trimming in the parser.
1 parent f7965bf commit 15441ec

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ impl Url {
12311231
if let Some(input) = fragment {
12321232
self.fragment_start = Some(to_u32(self.serialization.len()).unwrap());
12331233
self.serialization.push('#');
1234-
self.mutate(|parser| parser.parse_fragment(parser::Input::new(input)))
1234+
self.mutate(|parser| parser.parse_fragment(parser::Input::no_trim(input)))
12351235
} else {
12361236
self.fragment_start = None
12371237
}
@@ -1289,7 +1289,11 @@ impl Url {
12891289
let scheme_type = SchemeType::from(self.scheme());
12901290
let scheme_end = self.scheme_end;
12911291
self.mutate(|parser| {
1292-
parser.parse_query(scheme_type, scheme_end, parser::Input::new(input))
1292+
parser.parse_query(
1293+
scheme_type,
1294+
scheme_end,
1295+
parser::Input::trim_tab_and_newlines(input),
1296+
)
12931297
});
12941298
}
12951299

src/parser.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,13 @@ impl<'i> Input<'i> {
208208
}
209209
}
210210

211+
pub fn trim_tab_and_newlines(original_input: &'i str) -> Self {
212+
let input = original_input.trim_matches(ascii_tab_or_new_line);
213+
Input {
214+
chars: input.chars(),
215+
}
216+
}
217+
211218
pub fn with_log(original_input: &'i str, vfn: Option<&dyn Fn(SyntaxViolation)>) -> Self {
212219
let input = original_input.trim_matches(c0_control_or_space);
213220
if let Some(vfn) = vfn {
@@ -290,6 +297,17 @@ impl Pattern for char {
290297
}
291298
}
292299

300+
impl Pattern for String {
301+
fn split_prefix<'i>(self, input: &mut Input<'i>) -> bool {
302+
for c in self.chars() {
303+
if input.next() != Some(c) {
304+
return false;
305+
}
306+
}
307+
true
308+
}
309+
}
310+
293311
impl<'a> Pattern for &'a str {
294312
fn split_prefix<'i>(self, input: &mut Input<'i>) -> bool {
295313
for c in self.chars() {
@@ -447,7 +465,7 @@ impl<'a> Parser<'a> {
447465
.collect::<String>()
448466
!= "//"
449467
});
450-
if let Some(after_prefix) = input.split_prefix("//") {
468+
if let Some(after_prefix) = input.split_prefix("/".repeat(slashes_count as usize)) {
451469
return self.after_double_slash(after_prefix, scheme_type, scheme_end);
452470
} else {
453471
self.after_double_slash(remaining, scheme_type, scheme_end)
@@ -1535,7 +1553,7 @@ fn c0_control_or_space(ch: char) -> bool {
15351553

15361554
/// https://infra.spec.whatwg.org/#ascii-tab-or-newline
15371555
#[inline]
1538-
fn ascii_tab_or_new_line(ch: char) -> bool {
1556+
pub fn ascii_tab_or_new_line(ch: char) -> bool {
15391557
matches!(ch, '\t' | '\r' | '\n')
15401558
}
15411559

0 commit comments

Comments
 (0)