Reject invalid URIs that begin with ':'.

This commit is contained in:
Sergio Benitez 2021-04-27 20:14:31 -07:00
parent 068aacd79d
commit 3c8f5708ea
2 changed files with 18 additions and 4 deletions

View File

@ -141,9 +141,12 @@ pub fn absolute_only<'a>(input: &mut RawInput<'a>) -> Result<'a, Absolute<'a>> {
}
#[parser]
fn absolute_or_authority<'a>(
input: &mut RawInput<'a>,
) -> Result<'a, Uri<'a>> {
fn absolute_or_authority<'a>(input: &mut RawInput<'a>) -> Result<'a, Uri<'a>> {
// If the URI begins with `:`, it must follow with a `port`.
switch! {
peek(b':') => return Ok(Uri::Authority(authority(None)?)),
}
let start = parse_current_marker!();
let left = take_while(is_reg_name_char)?;
let mark_at_left = parse_current_marker!();

View File

@ -99,7 +99,18 @@ fn test_assert_no_parse() {
#[test]
fn bad_parses() {
assert_no_parse!("://z7:77777777777777777777777777777`77777777777");
assert_no_parse! {
"://z7:77777777777777777777777777777`77777777777",
// from #1621
"://@example.com/test",
"://example.com:/test",
"://@example.com:/test",
"://example.com/test?",
"://example.com:/test?",
"://@example.com/test?",
"://@example.com:/test?"
};
}
#[test]