Skip to content

Commit 4018195

Browse files
committed
UTF-8 percent encoding tests. Also fixed prefix slash trimming in the parser.
1 parent 3d41382 commit 4018195

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/lib.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ impl Url {
11751175
if let Some(input) = fragment {
11761176
self.fragment_start = Some(to_u32(self.serialization.len()).unwrap());
11771177
self.serialization.push('#');
1178-
self.mutate(|parser| parser.parse_fragment(parser::Input::new(input)))
1178+
self.mutate(|parser| parser.parse_fragment(parser::Input::no_trim(input)))
11791179
} else {
11801180
self.fragment_start = None
11811181
}
@@ -1233,7 +1233,11 @@ impl Url {
12331233
let scheme_type = SchemeType::from(self.scheme());
12341234
let scheme_end = self.scheme_end;
12351235
self.mutate(|parser| {
1236-
parser.parse_query(scheme_type, scheme_end, parser::Input::new(input))
1236+
parser.parse_query(
1237+
scheme_type,
1238+
scheme_end,
1239+
parser::Input::trim_tab_and_newlines(input),
1240+
)
12371241
});
12381242
}
12391243

src/parser.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ impl<'i> Input<'i> {
190190
}
191191
}
192192

193+
pub fn trim_tab_and_newlines(original_input: &'i str) -> Self {
194+
let input = original_input.trim_matches(ascii_tab_or_new_line);
195+
Input {
196+
chars: input.chars(),
197+
}
198+
}
199+
193200
pub fn with_log(original_input: &'i str, vfn: Option<&dyn Fn(SyntaxViolation)>) -> Self {
194201
let input = original_input.trim_matches(c0_control_or_space);
195202
if let Some(vfn) = vfn {
@@ -272,6 +279,17 @@ impl Pattern for char {
272279
}
273280
}
274281

282+
impl Pattern for String {
283+
fn split_prefix<'i>(self, input: &mut Input<'i>) -> bool {
284+
for c in self.chars() {
285+
if input.next() != Some(c) {
286+
return false;
287+
}
288+
}
289+
true
290+
}
291+
}
292+
275293
impl<'a> Pattern for &'a str {
276294
fn split_prefix<'i>(self, input: &mut Input<'i>) -> bool {
277295
for c in self.chars() {
@@ -429,7 +447,7 @@ impl<'a> Parser<'a> {
429447
.collect::<String>()
430448
!= "//"
431449
});
432-
if let Some(after_prefix) = input.split_prefix("//") {
450+
if let Some(after_prefix) = input.split_prefix("/".repeat(slashes_count as usize)) {
433451
return self.after_double_slash(after_prefix, scheme_type, scheme_end);
434452
} else {
435453
self.after_double_slash(remaining, scheme_type, scheme_end)
@@ -1517,7 +1535,7 @@ fn c0_control_or_space(ch: char) -> bool {
15171535

15181536
/// https://infra.spec.whatwg.org/#ascii-tab-or-newline
15191537
#[inline]
1520-
fn ascii_tab_or_new_line(ch: char) -> bool {
1538+
pub fn ascii_tab_or_new_line(ch: char) -> bool {
15211539
matches!(ch, '\t' | '\r' | '\n')
15221540
}
15231541

0 commit comments

Comments
 (0)