@@ -439,8 +439,14 @@ fn match_alert_operator(expr: &ConditionConfig) -> Expr {
439
439
// if it can be parsed as a number, then parse it
440
440
// else keep it as a string
441
441
if expr. value . as_ref ( ) . is_some_and ( |v| !v. is_empty ( ) ) {
442
- let value = expr. value . as_ref ( ) . unwrap ( ) ;
443
- let value = NumberOrString :: from_string ( value. clone ( ) ) ;
442
+ let string_value = expr
443
+ . value
444
+ . as_ref ( )
445
+ . unwrap ( )
446
+ . replace ( "'" , "\\ '" )
447
+ . replace ( '%' , "\\ %" )
448
+ . replace ( '_' , "\\ _" ) ;
449
+ let value = NumberOrString :: from_string ( string_value. clone ( ) ) ;
444
450
445
451
// for maintaining column case
446
452
let column = format ! ( r#""{}""# , expr. column) ;
@@ -451,28 +457,30 @@ fn match_alert_operator(expr: &ConditionConfig) -> Expr {
451
457
WhereConfigOperator :: GreaterThan => col ( column) . gt ( lit ( value) ) ,
452
458
WhereConfigOperator :: LessThanOrEqual => col ( column) . lt_eq ( lit ( value) ) ,
453
459
WhereConfigOperator :: GreaterThanOrEqual => col ( column) . gt_eq ( lit ( value) ) ,
454
- WhereConfigOperator :: ILike => col ( column) . ilike ( lit ( value) ) ,
455
- WhereConfigOperator :: Contains => col ( column) . like ( lit ( value) ) ,
460
+ WhereConfigOperator :: ILike => col ( column) . ilike ( lit ( string_value) ) ,
461
+ WhereConfigOperator :: Contains => {
462
+ col ( column) . like ( lit ( format ! ( "%{string_value}%" ) ) )
463
+ } ,
456
464
WhereConfigOperator :: BeginsWith => Expr :: BinaryExpr ( BinaryExpr :: new (
457
465
Box :: new ( col ( column) ) ,
458
466
Operator :: RegexIMatch ,
459
- Box :: new ( lit ( format ! ( "^{value }" ) ) ) ,
467
+ Box :: new ( lit ( format ! ( "^{string_value }" ) ) ) ,
460
468
) ) ,
461
469
WhereConfigOperator :: EndsWith => Expr :: BinaryExpr ( BinaryExpr :: new (
462
470
Box :: new ( col ( column) ) ,
463
471
Operator :: RegexIMatch ,
464
- Box :: new ( lit ( format ! ( "{value }$" ) ) ) ,
472
+ Box :: new ( lit ( format ! ( "{string_value }$" ) ) ) ,
465
473
) ) ,
466
- WhereConfigOperator :: DoesNotContain => col ( column) . not_ilike ( lit ( value ) ) ,
474
+ WhereConfigOperator :: DoesNotContain => col ( column) . not_ilike ( lit ( string_value ) ) ,
467
475
WhereConfigOperator :: DoesNotBeginWith => Expr :: BinaryExpr ( BinaryExpr :: new (
468
476
Box :: new ( col ( column) ) ,
469
477
Operator :: RegexNotIMatch ,
470
- Box :: new ( lit ( format ! ( "^{value }" ) ) ) ,
478
+ Box :: new ( lit ( format ! ( "^{string_value }" ) ) ) ,
471
479
) ) ,
472
480
WhereConfigOperator :: DoesNotEndWith => Expr :: BinaryExpr ( BinaryExpr :: new (
473
481
Box :: new ( col ( column) ) ,
474
482
Operator :: RegexNotIMatch ,
475
- Box :: new ( lit ( format ! ( "{value }$" ) ) ) ,
483
+ Box :: new ( lit ( format ! ( "{string_value }$" ) ) ) ,
476
484
) ) ,
477
485
_ => unreachable ! ( "value must not be null for operators other than `is null` and `is not null`. Should've been caught in validation" )
478
486
}
0 commit comments