From 650e9f24b685b418a1b3245ededdd97d126d8661 Mon Sep 17 00:00:00 2001 From: Jack Perkins Date: Sat, 3 May 2025 14:13:15 +0200 Subject: [PATCH 1/3] Add failing test for links with multiple hash characters --- tests/links.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/links.rs b/tests/links.rs index 786ac00..26c7b78 100644 --- a/tests/links.rs +++ b/tests/links.rs @@ -25,6 +25,7 @@ fn basic_parsing() { "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", + "https://matrix.to/#/#deltachat:matrix.org" ]; let test_cases_with_puny = vec!["https://ü.app#help", "http://münchen.de"]; From 76b87c6701a5153b53cde20ef50c9a33a3ebe08a Mon Sep 17 00:00:00 2001 From: Jack Perkins Date: Sat, 3 May 2025 15:28:05 +0200 Subject: [PATCH 2/3] Allow ifragment part of links to have multiple hash characters --- src/parser/link_url/parse_link.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parser/link_url/parse_link.rs b/src/parser/link_url/parse_link.rs index 1011aaf..43efa2f 100644 --- a/src/parser/link_url/parse_link.rs +++ b/src/parser/link_url/parse_link.rs @@ -237,7 +237,7 @@ fn take_while_pct_encoded(input: &str) -> IResult<&str, &str, CustomError<&str>> } fn ifragment(input: &str) -> IResult<&str, &str, CustomError<&str>> { - recognize(tuple((char('#'), take_while_ifragment)))(input) + recognize(many0(tuple((char('#'), take_while_ifragment))))(input) } fn parse_ipath_abempty(input: &str) -> IResult<&str, &str, CustomError<&str>> { From 7263695af71ba51a967436e93db43ff55627b791 Mon Sep 17 00:00:00 2001 From: Jack Perkins Date: Wed, 14 May 2025 20:58:03 +0200 Subject: [PATCH 3/3] separate link parsing multiple hashes test to own function --- tests/links.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/links.rs b/tests/links.rs index 26c7b78..036ec08 100644 --- a/tests/links.rs +++ b/tests/links.rs @@ -25,7 +25,6 @@ fn basic_parsing() { "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", - "https://matrix.to/#/#deltachat:matrix.org" ]; let test_cases_with_puny = vec!["https://ü.app#help", "http://münchen.de"]; @@ -50,6 +49,21 @@ fn basic_parsing() { } } +#[test] +fn multiple_hashes() { + assert_eq!( + LinkDestination::parse("https://matrix.to/#/#deltachat:matrix.org") + .unwrap() + .1, + LinkDestination { + hostname: Some("matrix.to"), + target: "https://matrix.to/#/#deltachat:matrix.org", + scheme: "https", + punycode: None, + } + ); +} + #[test] fn bare_scheme_no_parse() { // bare scheme shouldn't be linkified