summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2021-05-17 12:49:25 +0000
committerAaron Bohy <aab@odoo.com>2021-05-17 13:18:13 +0000
commit44e185dbd6ddeda7cdcd76882fa0bd231e9d3f37 (patch)
treecf9e3a49dde2bbd2dc65ac12562696df500836c2 /addons/web/static/src
parent7873144a9f1e68943d14053c3e5d6a945a46e9d5 (diff)
[FIX] web: domain: (=)(i)like operators
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) <ged@openerp.com>
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/core/domain.js21
1 files changed, 16 insertions, 5 deletions
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(