fix: handling of epsilon transitions

This commit is contained in:
shreyas-londhe
2025-02-12 16:31:40 +05:30
parent f8518da3d7
commit b80f2ea047
2 changed files with 21 additions and 0 deletions

View File

@@ -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"
]
}
]

View File

@@ -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,