@@ -24,12 +24,12 @@ QueryBuilder.defaults({
24
24
greater_or_equal : { op : '>= ?' } ,
25
25
between : { op : 'BETWEEN ?' , sep : ' AND ' } ,
26
26
not_between : { op : 'NOT BETWEEN ?' , sep : ' AND ' } ,
27
- begins_with : { op : 'LIKE(?) ' , mod : '{0}%' } ,
28
- not_begins_with : { op : 'NOT LIKE(?) ' , mod : '{0}%' } ,
29
- contains : { op : 'LIKE(?) ' , mod : '%{0}%' } ,
30
- not_contains : { op : 'NOT LIKE(?) ' , mod : '%{0}%' } ,
31
- ends_with : { op : 'LIKE(?) ' , mod : '%{0}' } ,
32
- not_ends_with : { op : 'NOT LIKE(?) ' , mod : '%{0}' } ,
27
+ begins_with : { op : 'LIKE ? ' , mod : '{0}%' , escape : '%_ ' } ,
28
+ not_begins_with : { op : 'NOT LIKE ? ' , mod : '{0}%' , escape : '%_ ' } ,
29
+ contains : { op : 'LIKE ? ' , mod : '%{0}%' , escape : '%_ ' } ,
30
+ not_contains : { op : 'NOT LIKE ? ' , mod : '%{0}%' , escape : '%_ ' } ,
31
+ ends_with : { op : 'LIKE ? ' , mod : '%{0}' , escape : '%_ ' } ,
32
+ not_ends_with : { op : 'NOT LIKE ? ' , mod : '%{0}' , escape : '%_ ' } ,
33
33
is_empty : { op : '= \'\'' } ,
34
34
is_not_empty : { op : '!= \'\'' } ,
35
35
is_null : { op : 'IS NULL' } ,
@@ -307,7 +307,7 @@ QueryBuilder.extend(/** @lends module:plugins.SqlSupport.prototype */ {
307
307
v = v ? 1 : 0 ;
308
308
}
309
309
else if ( ! stmt && rule . type !== 'integer' && rule . type !== 'double' && rule . type !== 'boolean' ) {
310
- v = Utils . escapeString ( v ) ;
310
+ v = Utils . escapeString ( v , sql . escape ) ;
311
311
}
312
312
313
313
if ( sql . mod ) {
@@ -579,6 +579,19 @@ QueryBuilder.extend(/** @lends module:plugins.SqlSupport.prototype */ {
579
579
Utils . error ( 'SQLParse' , 'Cannot find field name in {0}' , JSON . stringify ( data . left ) ) ;
580
580
}
581
581
582
+ // unescape chars declared by the operator
583
+ var finalValue = opVal . val ;
584
+ var sql = self . settings . sqlOperators [ opVal . op ] ;
585
+ if ( ! stmt && sql && sql . escape ) {
586
+ var searchChars = sql . escape . split ( '' ) . map ( function ( c ) {
587
+ return '\\\\' + c ;
588
+ } ) . join ( '|' ) ;
589
+ finalValue = finalValue
590
+ . replace ( new RegExp ( '(' + searchChars + ')' , 'g' ) , function ( s ) {
591
+ return s [ 1 ] ;
592
+ } ) ;
593
+ }
594
+
582
595
var id = self . getSQLFieldID ( field , value ) ;
583
596
584
597
/**
@@ -593,7 +606,7 @@ QueryBuilder.extend(/** @lends module:plugins.SqlSupport.prototype */ {
593
606
id : id ,
594
607
field : field ,
595
608
operator : opVal . op ,
596
- value : opVal . val
609
+ value : finalValue
597
610
} , data ) ;
598
611
599
612
curr . rules . push ( rule ) ;
0 commit comments