Skip to content

Commit

Permalink
fix: bug introduced in 895a614.
Browse files Browse the repository at this point in the history
The regex `/a.*/` was not producing a warning, but it should.
  • Loading branch information
plusvic committed Dec 16, 2024
1 parent c0e58a4 commit 4a87b68
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/src/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2149,8 +2149,8 @@ impl<'a> Compiler<'a> {
MinMaxResult::NoElements => true,
// Only one atom shorter than 2 bytes, slow pattern.
MinMaxResult::OneElement(len) if len < 2 => true,
// More than one atom, but all shorter than 2 bytes.
MinMaxResult::MinMax(_, max) if max < 2 => true,
// More than one atom, at least one is shorter than 2 bytes.
MinMaxResult::MinMax(min, _) if min < 2 => true,
// More than 2700 atoms, all with exactly 2 bytes.
// Why 2700?. The larger the number of atoms the higher the
// odds of finding one of them in the data, which slows down
Expand Down
11 changes: 9 additions & 2 deletions lib/src/compiler/tests/testdata/warnings/23.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
rule test {
rule test_1 {
strings:
$a = {00 [1-10] 01}
condition:
condition:
$a
}

rule test_2 {
strings:
$a = /a.*/
condition:
$a
}
6 changes: 6 additions & 0 deletions lib/src/compiler/tests/testdata/warnings/23.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ warning[slow_pattern]: slow pattern
3 | $a = {00 [1-10] 01}
| ------------------ this pattern may slow down the scan
|
warning[slow_pattern]: slow pattern
--> line:10:4
|
10 | $a = /a.*/
| ---------- this pattern may slow down the scan
|
8 changes: 2 additions & 6 deletions py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,8 @@ impl Compiler {
error_on_slow_pattern: bool,
) -> yrx::Compiler<'static> {
let mut compiler = yrx::Compiler::new();
if relaxed_re_syntax {
compiler.relaxed_re_syntax(true);
}
if error_on_slow_pattern {
compiler.error_on_slow_pattern(true);
}
compiler.relaxed_re_syntax(relaxed_re_syntax);
compiler.error_on_slow_pattern(error_on_slow_pattern);
compiler
}
}
Expand Down

0 comments on commit 4a87b68

Please sign in to comment.