mirror of
https://github.com/zkemail/zk-regex.git
synced 2026-01-10 06:07:58 -05:00
fix: handling of epsilon transitions
This commit is contained in:
@@ -37,5 +37,21 @@
|
||||
"regex": "^[a-zA-Z]{2,}\\s[a-zA-Z]{1,}'?-?[a-zA-Z]{2,}\\s?([a-zA-Z]{1,})?$",
|
||||
"pass": ["John Doe", "Mary Jane", "Robert O'Neill", "Sarah Jane-Smith"],
|
||||
"fail": ["J D", "John", "John Doe", "12John Doe"]
|
||||
},
|
||||
{
|
||||
"regex": "(\r\n|^)to:([^\r\n]+<)?([^@]{1,3})([^@]*)@([a-zA-Z0-9.-]+)>?\r\n",
|
||||
"pass": [
|
||||
"to:user@example.com\r\n",
|
||||
"to:\"John Doe\" <john@example.com>\r\n",
|
||||
"to:abc@domain.com\r\n",
|
||||
"to:abcd@example.com\r\n",
|
||||
"\r\nto:user+tag@example.com\r\n"
|
||||
],
|
||||
"fail": [
|
||||
"to:@example.com\r\n",
|
||||
"to:user@\r\n",
|
||||
"from:user@example.com\r\n",
|
||||
"to:user@example.com"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
@@ -985,6 +985,11 @@ pub(crate) fn get_regex_and_dfa(
|
||||
.map(|regex| regex.regex_def.as_str())
|
||||
.collect::<String>();
|
||||
|
||||
// Remove epsilon transitions
|
||||
for state in &mut net_dfa_graph.states {
|
||||
state.transitions.retain(|_, chars| !chars.is_empty());
|
||||
}
|
||||
|
||||
Ok(RegexAndDFA {
|
||||
regex_pattern: regex_str,
|
||||
dfa: net_dfa_graph,
|
||||
|
||||
Reference in New Issue
Block a user