diff --git a/src/parser/link_url/parse_link.rs b/src/parser/link_url/parse_link.rs index f4e288b..c6b05b8 100644 --- a/src/parser/link_url/parse_link.rs +++ b/src/parser/link_url/parse_link.rs @@ -333,6 +333,38 @@ fn get_correct_link(link: &str) -> Option { None } +fn parse_ipath_abempty(input: &str) -> IResult<&str, &str, CustomError<&str>> { + recognize(many0(tuple((char('/'), opt(take_while_ipchar1)))))(input) +} + +#[test] +fn test_ipath_abempty() { + assert_eq!( + parse_ipath_abempty("///foo/bar").unwrap(), + ("", "///foo/bar") + ); +} + +fn parse_ipath_absolute(input: &str) -> IResult<&str, &str, CustomError<&str>> { + recognize(tuple(( + char('/'), + opt(tuple(( + take_while_ipchar1, + many0(tuple((char('/'), opt(take_while_ipchar1)))), + ))), + )))(input) +} + +#[test] +fn test_ipath_absolute() { + assert_eq!(parse_ipath_absolute("/foo").unwrap(), ("", "/foo")); + assert_eq!(parse_ipath_absolute("/foo/bar").unwrap(), ("", "/foo/bar")); + assert_eq!( + parse_ipath_absolute("/foo//bar").unwrap(), + ("", "/foo//bar") + ); +} + // IRI links per RFC3987 and RFC3986 fn parse_iri(input: &str) -> IResult<&str, LinkDestination, CustomError<&str>> { let input_ = <&str>::clone(&input); @@ -345,13 +377,8 @@ fn parse_iri(input: &str) -> IResult<&str, LinkDestination, CustomError<&str>> { // host is actually part of authority but we need it separately // see iauthority function description for more information let (input, path) = opt(alt(( - recognize(tuple(( - char('/'), - opt(tuple(( - take_while_ipchar1, - many0(tuple((char('/'), opt(take_while_ipchar1)))), - ))), - ))), // ipath-absolute + parse_ipath_abempty, + parse_ipath_absolute, recognize(tuple(( take_while_ipchar, many0(tuple((char('/'), opt(take_while_ipchar1)))), diff --git a/tests/links.rs b/tests/links.rs index 0f8f94a..786ac00 100644 --- a/tests/links.rs +++ b/tests/links.rs @@ -23,6 +23,8 @@ fn basic_parsing() { "mailto:delta@example.com?subject=hi&body=hello%20world", "mailto:foö@ü.chat", "ftp://test-test", + "https://www.openmandriva.org/en/news/article/openmandriva-rome-24-07-released", + "https://www.openmandriva.org///en/news/article/openmandriva-rome-24-07-released", ]; let test_cases_with_puny = vec!["https://ü.app#help", "http://münchen.de"];