Skip to content

Commit

Permalink
regex: fix another inner literal bug
Browse files Browse the repository at this point in the history
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
  • Loading branch information
BurntSushi committed Apr 2, 2020
1 parent 3d6a58f commit 1c4b5ad
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
TBD
===
Bug fixes:

* [BUG #1537](https://github.com/BurntSushi/ripgrep/issues/1537):
Fix match bug caused by inner literal optimization.


12.0.1 (2020-03-29)
===================
ripgrep 12.0.1 is a small patch release that includes a minor bug fix relating
Expand Down
21 changes: 15 additions & 6 deletions crates/regex/src/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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(";"),);
}
}
8 changes: 8 additions & 0 deletions tests/regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,3 +791,11 @@ rgtest!(
eqnice!("repotree/not-ignored\n", cmd.stdout());
}
);

// See: https://github.com/BurntSushi/ripgrep/issues/1537
rgtest!(r1537, |dir: Dir, mut cmd: TestCommand| {
dir.create("foo", "abc;de,fg");

let expected = "foo:abc;de,fg\n";
eqnice!(expected, cmd.arg(";(.*,){1}").stdout());
});

0 comments on commit 1c4b5ad

Please sign in to comment.