From 62c9550fbbe171769510c347ca6dbb7974ebcc85 Mon Sep 17 00:00:00 2001 From: Farooq Karimi Zadeh Date: Sat, 8 Jun 2024 18:12:23 +0330 Subject: [PATCH] fix #76 --- src/parser/link_url/parse_link.rs | 12 +++++++----- tests/links.rs | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/parser/link_url/parse_link.rs b/src/parser/link_url/parse_link.rs index f4e288b..8e2afdc 100644 --- a/src/parser/link_url/parse_link.rs +++ b/src/parser/link_url/parse_link.rs @@ -132,7 +132,9 @@ fn iauthority(input: &str) -> IResult<&str, (&str, &str, bool), CustomError<&str let (input, port) = opt(recognize(tuple((char(':'), take_while(is_digit)))))(input)?; let userinfo = userinfo.unwrap_or(""); let port = port.unwrap_or(""); - let len = userinfo.len().saturating_add(port.len()); + let len = userinfo.len() + .saturating_add(port.len()); + if let Some(out) = i.get(0..len) { Ok((input, (out, host, is_ipv6_or_future))) } else { @@ -142,10 +144,10 @@ fn iauthority(input: &str) -> IResult<&str, (&str, &str, bool), CustomError<&str /// Consume an iuserinfo fn take_while_iuserinfo(input: &str) -> IResult<&str, &str, CustomError<&str>> { - alt(( - recognize(many0(take_while_pct_encoded)), - take_while(is_iuserinfo_not_pct_encoded), - ))(input) + recognize(many1(alt(( + recognize(many1(take_while_pct_encoded)), + take_while1(is_iuserinfo_not_pct_encoded), + ))))(input) } fn is_iuserinfo_not_pct_encoded(c: char) -> bool { diff --git a/tests/links.rs b/tests/links.rs index e4c3fbe..6146629 100644 --- a/tests/links.rs +++ b/tests/links.rs @@ -200,4 +200,5 @@ fn dclogin_link() { assert!(link_destination.punycode.is_none()); assert_eq!(link_destination.scheme, "dclogin"); assert_eq!(link_destination.target, link); + assert_eq!(link_destination.hostname, Some("nine.testrun.org")); }