Skip to content

Commit b80f2ea

Browse files
fix: handling of epsilon transitions
1 parent f8518da commit b80f2ea

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

packages/compiler/src/dfa_tests.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,21 @@
3737
"regex": "^[a-zA-Z]{2,}\\s[a-zA-Z]{1,}'?-?[a-zA-Z]{2,}\\s?([a-zA-Z]{1,})?$",
3838
"pass": ["John Doe", "Mary Jane", "Robert O'Neill", "Sarah Jane-Smith"],
3939
"fail": ["J D", "John", "John Doe", "12John Doe"]
40+
},
41+
{
42+
"regex": "(\r\n|^)to:([^\r\n]+<)?([^@]{1,3})([^@]*)@([a-zA-Z0-9.-]+)>?\r\n",
43+
"pass": [
44+
45+
"to:\"John Doe\" <[email protected]>\r\n",
46+
47+
48+
"\r\nto:[email protected]\r\n"
49+
],
50+
"fail": [
51+
"to:@example.com\r\n",
52+
"to:user@\r\n",
53+
"from:[email protected]\r\n",
54+
55+
]
4056
}
4157
]

packages/compiler/src/regex.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,11 @@ pub(crate) fn get_regex_and_dfa(
985985
.map(|regex| regex.regex_def.as_str())
986986
.collect::<String>();
987987

988+
// Remove epsilon transitions
989+
for state in &mut net_dfa_graph.states {
990+
state.transitions.retain(|_, chars| !chars.is_empty());
991+
}
992+
988993
Ok(RegexAndDFA {
989994
regex_pattern: regex_str,
990995
dfa: net_dfa_graph,

0 commit comments

Comments
 (0)