Skip to content

Commit 73589cc

Browse files
committed
Handle invalid authority.
1 parent 70692ab commit 73589cc

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/parser.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ macro_rules! simple_enum_error {
7070

7171
simple_enum_error! {
7272
EmptyHost => "empty host",
73+
InvalidAuthority => "invalid authority",
7374
IdnaError => "invalid international domain name",
7475
InvalidPort => "invalid port number",
7576
InvalidIpv4Address => "invalid IPv4 address",
@@ -872,7 +873,19 @@ impl<'a> Parser<'a> {
872873
}
873874
let (mut userinfo_char_count, remaining) = match last_at {
874875
None => return Ok((to_u32(self.serialization.len())?, input)),
875-
Some((0, remaining)) => return Ok((to_u32(self.serialization.len())?, remaining)),
876+
Some((0, remaining)) => {
877+
// Otherwise, if one of the following is true
878+
// c is the EOF code point, U+002F (/), U+003F (?), or U+0023 (#)
879+
// url is special and c is U+005C (\)
880+
// If @ flag is set and buffer is the empty string, validation error, return failure.
881+
if let (Some(c), _) = remaining.split_first() {
882+
if c == '/' || c == '?' || c == '#'
883+
|| scheme_type.is_special() && c == '\\' {
884+
return Err(ParseError::InvalidAuthority);
885+
}
886+
}
887+
return Ok((to_u32(self.serialization.len())?, remaining));
888+
}
876889
Some(x) => x,
877890
};
878891

0 commit comments

Comments
 (0)