Skip to content

Commit

Permalink
fix bot command suggestion with @- char was detected as email address
Browse files Browse the repository at this point in the history
fixes #53
  • Loading branch information
Simon-Laux committed Nov 15, 2023
1 parent 1237482 commit d564eb9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

### Fixed
- fix bot command suggestion with `@`- char was detected as email address

## 0.8.0 - Nom 7 and more Generic URI Schemes

### Changed
Expand Down
6 changes: 3 additions & 3 deletions docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ while !remaining_input.is_empty() {
let res = {
// try the following parsers in this order (order is important with some parsers)
1. hashtag(input)
2. email_address(input)
3. link(input)
4. bot_command_suggestion(input)
2. bot_command_suggestion(input)
3. email_address(input)
4. link(input)
5. linebreak(input)
last option: consumes all text until [parse_text_element] works again
}
Expand Down
8 changes: 4 additions & 4 deletions src/parser/parse_from_text/text_elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,6 @@ pub(crate) fn parse_text_element(

if let Ok((i, elm)) = hashtag(input) {
Ok((i, elm))
} else if let Ok((i, elm)) = email_address(input) {
Ok((i, elm))
} else if let Ok((i, elm)) = link(input) {
Ok((i, elm))
} else if let Ok((i, elm)) = {
if prev_char == Some(' ') || prev_char.is_none() {
bot_command_suggestion(input)
Expand All @@ -275,6 +271,10 @@ pub(crate) fn parse_text_element(
}
} {
Ok((i, elm))
} else if let Ok((i, elm)) = email_address(input) {
Ok((i, elm))
} else if let Ok((i, elm)) = link(input) {
Ok((i, elm))
} else if let Ok((i, _)) = linebreak(input) {
Ok((i, Element::Linebreak))
} else {
Expand Down
28 changes: 28 additions & 0 deletions tests/text_to_ast/text_only.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,3 +609,31 @@ fn link_in_parenthesis2() {
]
);
}


#[test]
fn bot_suggestion_is_no_email() {
assert_eq!(
parse_only_text("/command@[email protected]"),
vec![
BotCommandSuggestion("/command@[email protected]"),
]
);
assert_eq!(
parse_only_text("\n/command@[email protected]"),
vec![
Linebreak,
BotCommandSuggestion("/command@[email protected]"),
]
);

assert_eq!(
parse_only_text("Bots that can be selected \n/command@[email protected] BOT"),
vec![
Text("Bots that can be selected "),
Linebreak,
BotCommandSuggestion("/command@[email protected]"),
Text(" BOT"),
]
);
}

0 comments on commit d564eb9

Please sign in to comment.