From 44e185dbd6ddeda7cdcd76882fa0bd231e9d3f37 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Mon, 17 May 2021 12:49:25 +0000 Subject: [FIX] web: domain: (=)(i)like operators MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, evaluating a domain containing a like/ilike operator with an evaluation context in which the value was false crashed. Moreover, those operators were wrong w.r.t. the case sensitivity: like was case insensitive, whereas ilike was case sensitive, and both =like and =ilike were case insensitive. This commit fixes thoses issues. The first issue was spotted on our prod, as we tried to add an invisible attrs in a form view, using the ilike operator (it thus crashed in create mode). The second issue was spotted while writting the test cases. To the best of our knowledge, those operators aren't used in attrs (for now), explaining why those issues haven't been found before. closes odoo/odoo#70876 Signed-off-by: Géry Debongnie (ged) --- addons/web/static/src/js/core/domain.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'addons/web/static/src/js/core/domain.js') diff --git a/addons/web/static/src/js/core/domain.js b/addons/web/static/src/js/core/domain.js index dbf2b18eb40..a1d6e7e7c49 100644 --- a/addons/web/static/src/js/core/domain.js +++ b/addons/web/static/src/js/core/domain.js @@ -106,20 +106,31 @@ var Domain = collections.Tree.extend({ return _.intersection( _.isArray(this._data[2]) ? this._data[2] : [this._data[2]], _.isArray(fieldValue) ? fieldValue : [fieldValue], - ).length !== 0;; + ).length !== 0; case "not in": return _.intersection( _.isArray(this._data[2]) ? this._data[2] : [this._data[2]], _.isArray(fieldValue) ? fieldValue : [fieldValue], ).length === 0; case "like": - return (fieldValue.toLowerCase().indexOf(this._data[2].toLowerCase()) >= 0); + if (fieldValue === false) { + return false; + } + return (fieldValue.indexOf(this._data[2]) >= 0); case "=like": - var regExp = new RegExp(this._data[2].toLowerCase().replace(/([.\[\]\{\}\+\*])/g, '\\\$1').replace(/%/g, '.*')); - return regExp.test(fieldValue.toLowerCase()); + if (fieldValue === false) { + return false; + } + return new RegExp(this._data[2].replace(/%/g, '.*')).test(fieldValue); case "ilike": - return (fieldValue.indexOf(this._data[2]) >= 0); + if (fieldValue === false) { + return false; + } + return (fieldValue.toLowerCase().indexOf(this._data[2].toLowerCase()) >= 0); case "=ilike": + if (fieldValue === false) { + return false; + } return new RegExp(this._data[2].replace(/%/g, '.*'), 'i').test(fieldValue); default: throw new Error(_.str.sprintf( -- cgit v1.2.3