diff options
author | Andrew Gallant <jamslam@gmail.com> | 2020-04-01 20:34:39 -0400 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2020-04-01 20:37:48 -0400 |
commit | 1c4b5adb7b4a239e433d4a1dc2aa4b09ee30573d (patch) | |
tree | a4947ad1f3e1676c9b578b7091dcf4901fea6a3f /crates | |
parent | 3d6a58faffc025861a977a8c09375d96a9b1452c (diff) |
regex: fix another inner literal bug
It looks like `is_simple` wasn't quite correct.
I can't wait until this code is rewritten. It is still not quite clearly
correct to me.
Fixes #1537
Diffstat (limited to 'crates')
-rw-r--r-- | crates/regex/src/literal.rs | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/crates/regex/src/literal.rs b/crates/regex/src/literal.rs index f1184fa1..a18dcb17 100644 --- a/crates/regex/src/literal.rs +++ b/crates/regex/src/literal.rs @@ -326,12 +326,12 @@ fn is_simple(expr: &Hir) -> bool { HirKind::Empty | HirKind::Literal(_) | HirKind::Class(_) - | HirKind::Repetition(_) | HirKind::Concat(_) | HirKind::Alternation(_) => true, - HirKind::Anchor(_) | HirKind::WordBoundary(_) | HirKind::Group(_) => { - false - } + HirKind::Anchor(_) + | HirKind::WordBoundary(_) + | HirKind::Group(_) + | HirKind::Repetition(_) => false, } } @@ -412,8 +412,17 @@ mod tests { // https://github.com/BurntSushi/ripgrep/issues/1319 assert_eq!( one_regex(r"TTGAGTCCAGGAG[ATCG]{2}C"), - pat("TTGAGTCCAGGAGA|TTGAGTCCAGGAGC|\ - TTGAGTCCAGGAGG|TTGAGTCCAGGAGT") + pat("TTGAGTCCAGGAG"), ); } + + #[test] + fn regression_1537() { + // Regression from: + // https://github.com/BurntSushi/ripgrep/issues/1537 + assert_eq!(one_regex(r";(.*,)"), pat(";")); + assert_eq!(one_regex(r";((.*,))"), pat(";")); + assert_eq!(one_regex(r";(.*,)+"), pat(";"),); + assert_eq!(one_regex(r";(.*,){1}"), pat(";"),); + } } |