Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse fediverse handles as text #84

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- fix: parse fediverse addresses as text, so they are not mistaken for email addresses ([issue #82](https://github.com/deltachat/message-parser/issues/82))

## 0.11.0 - Bug fixes for Link Parsing

### Fixed
Expand Down
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;
Loading