1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2025-06-14 22:15:13 +02:00

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
This commit is contained in:
Andrew Gallant
2020-04-01 20:34:39 -04:00
parent 3d6a58faff
commit 1c4b5adb7b
3 changed files with 31 additions and 6 deletions

View File

@ -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(";"),);
}
}