Skip to content

Commit d013318

Browse files
authored
fix: Properly derive max length of regexes when using alterations (#92)
1 parent 7a12bc6 commit d013318

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/regex_repr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn string_length_recursively(hir: &Hir) -> Result<(usize, Option<usize>)> {
6060
.collect::<std::result::Result<Vec<_>, _>>()?;
6161
(
6262
inner.iter().map(|x| x.0).min().unwrap_or(0),
63-
inner.iter().map(|x| x.0).max(),
63+
inner.iter().flat_map(|x| x.1).max(),
6464
)
6565
}
6666
// A class's length is always a single character and therefore has length 1

tests/test_extre.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
(r"[0-9]{2}[0-9a-zA-Z]{2,4}", 4, 6),
2222
(r"^[0-9]{2}[0-9a-zA-Z]{2,4}$", 4, 6),
2323
(r"^[0-9]{2}[0-9a-zA-Z]{2,4}.+$", 5, None),
24+
(r"^[A-Z][0-9]{2}(\*|(\.[0-9]{1,2}[*!]?))?$", 3, 7),
2425
],
2526
)
2627
def test_matching_string_length(

0 commit comments

Comments
 (0)