@@ -24,12 +24,12 @@ QueryBuilder.defaults({
2424 greater_or_equal : { op : '>= ?' } ,
2525 between : { op : 'BETWEEN ?' , sep : ' AND ' } ,
2626 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 : '%_ ' } ,
3333 is_empty : { op : '= \'\'' } ,
3434 is_not_empty : { op : '!= \'\'' } ,
3535 is_null : { op : 'IS NULL' } ,
@@ -307,7 +307,7 @@ QueryBuilder.extend(/** @lends module:plugins.SqlSupport.prototype */ {
307307 v = v ? 1 : 0 ;
308308 }
309309 else if ( ! stmt && rule . type !== 'integer' && rule . type !== 'double' && rule . type !== 'boolean' ) {
310- v = Utils . escapeString ( v ) ;
310+ v = Utils . escapeString ( v , sql . escape ) ;
311311 }
312312
313313 if ( sql . mod ) {
@@ -579,6 +579,19 @@ QueryBuilder.extend(/** @lends module:plugins.SqlSupport.prototype */ {
579579 Utils . error ( 'SQLParse' , 'Cannot find field name in {0}' , JSON . stringify ( data . left ) ) ;
580580 }
581581
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+
582595 var id = self . getSQLFieldID ( field , value ) ;
583596
584597 /**
@@ -593,7 +606,7 @@ QueryBuilder.extend(/** @lends module:plugins.SqlSupport.prototype */ {
593606 id : id ,
594607 field : field ,
595608 operator : opVal . op ,
596- value : opVal . val
609+ value : finalValue
597610 } , data ) ;
598611
599612 curr . rules . push ( rule ) ;
0 commit comments