Skip to content

Commit

Permalink
parse fediverse handles as text
Browse files Browse the repository at this point in the history
closes #82
  • Loading branch information
Simon-Laux committed Jan 3, 2025
1 parent 3692d75 commit a4f8491
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/parser/parse_from_text/text_elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ pub(crate) fn email_address(input: &str) -> IResult<&str, Element, CustomError<&
}
}

// see https://github.com/deltachat/message-parser/issues/82
pub(crate) fn fediverse_address_as_text(input: &str) -> IResult<&str, Element, CustomError<&str>> {
let (input, consumed) = recognize(tuple((tag("@"), email_address)))(input)?;
Ok((input, Element::Text(consumed)))
}

/*
fn not_link_part_char(c: char) -> bool {
!matches!(c, ':' | '\n' | '\r' | '\t' | ' ')
Expand Down Expand Up @@ -276,6 +282,8 @@ pub(crate) fn parse_text_element(
}
} {
Ok((i, elm))
} else if let Ok((i, elm)) = fediverse_address_as_text(input) {
Ok((i, elm))
} else if let Ok((i, elm)) = email_address(input) {
Ok((i, elm))
} else if let Ok((i, destination)) = LinkDestination::parse(input) {
Expand Down
41 changes: 41 additions & 0 deletions tests/based_on_issue/fediverse_handle_82.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use deltachat_message_parser::parser::Element::*;
use deltachat_message_parser::parser::{parse_desktop_set, parse_markdown_text, parse_only_text};

/// don't parse fediverse handles as email addresses.
/// as disscussed in https://github.com/deltachat/message-parser/issues/82
#[test]
fn text_only_fediverse_address_should_be_parsed_as_text() {
assert_eq!(
parse_only_text("you can reach me on @[email protected]!"),
vec![
Text("you can reach me on "),
Text("@[email protected]"),
Text("!")
]
);
}

#[test]
fn desktop_set_fediverse_address_should_be_parsed_as_text() {
assert_eq!(
parse_desktop_set("you can reach me on @[email protected]!"),
vec![
Text("you can reach me on "),
Text("@[email protected]"),
Text("!")
]
);
}

#[test]
fn markdown_fediverse_address_should_be_parsed_as_text() {
assert_eq!(
parse_markdown_text("you can reach me on @[email protected]!"),
vec![
Text("you can reach me on "),
Text("@[email protected]"),
Text("!")
]
);
}
1 change: 1 addition & 0 deletions tests/based_on_issue/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod fediverse_handle_82;
1 change: 1 addition & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod based_on_issue;
mod emoji;
mod links;
mod text_to_ast;

0 comments on commit a4f8491

Please sign in to comment.