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/tests/core/domain_tests.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'addons/web/static/tests/core') diff --git a/addons/web/static/tests/core/domain_tests.js b/addons/web/static/tests/core/domain_tests.js index ff30c53fc0f..fd94db6ec64 100644 --- a/addons/web/static/tests/core/domain_tests.js +++ b/addons/web/static/tests/core/domain_tests.js @@ -158,5 +158,29 @@ QUnit.module('core', {}, function () { assert.strictEqual(arrayToString(), '[]'); }); + + QUnit.test("like, =like, ilike and =ilike", function (assert) { + assert.expect(16); + + assert.ok(new Domain([['a', 'like', 'value']]).compute({ a: 'value' })); + assert.ok(new Domain([['a', 'like', 'value']]).compute({ a: 'some value' })); + assert.notOk(new Domain([['a', 'like', 'value']]).compute({ a: 'Some Value' })); + assert.notOk(new Domain([['a', 'like', 'value']]).compute({ a: false })); + + assert.ok(new Domain([['a', '=like', '%value']]).compute({ a: 'value' })); + assert.ok(new Domain([['a', '=like', '%value']]).compute({ a: 'some value' })); + assert.notOk(new Domain([['a', '=like', '%value']]).compute({ a: 'Some Value' })); + assert.notOk(new Domain([['a', '=like', '%value']]).compute({ a: false })); + + assert.ok(new Domain([['a', 'ilike', 'value']]).compute({ a: 'value' })); + assert.ok(new Domain([['a', 'ilike', 'value']]).compute({ a: 'some value' })); + assert.ok(new Domain([['a', 'ilike', 'value']]).compute({ a: 'Some Value' })); + assert.notOk(new Domain([['a', 'ilike', 'value']]).compute({ a: false })); + + assert.ok(new Domain([['a', '=ilike', '%value']]).compute({ a: 'value' })); + assert.ok(new Domain([['a', '=ilike', '%value']]).compute({ a: 'some value' })); + assert.ok(new Domain([['a', '=ilike', '%value']]).compute({ a: 'Some Value' })); + assert.notOk(new Domain([['a', '=ilike', '%value']]).compute({ a: false })); + }); }); }); -- cgit v1.2.3