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

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

Merged
merged 2 commits into from
Nov 16, 2023
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
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
22 changes: 22 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,25 @@ 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"),
]
);
}
Loading