diff options
| author | Mathieu Duckerts-Antoine <dam@odoo.com> | 2019-02-12 10:17:58 +0000 |
|---|---|---|
| committer | Mathieu Duckerts-Antoine <dam@odoo.com> | 2019-02-15 12:38:22 +0000 |
| commit | 84abddfe904273daaa3be744b974c8cce98c30fb (patch) | |
| tree | 47713cc8496aa8f0806c25364ddb8a7f4ddf3240 /addons/web/static/tests/core | |
| parent | 988e7690736be038dea7c52f3ecd4797fa793366 (diff) | |
[FIX] web: quotes and backslashes in search view
The commit 6d3ada1
aimed to solve problems occuring whith (single or
double) quotes when creating new custom filters.
Unfortunately, the point was missed and bugs were
still present. The present commit solves the
orginial problem satisfactorily.
There was also a problem in the management of
backslashes. Type '\\' in the search bar would
lead to a domain like
[('...', 'ilike', '\\\\\\\\\\\\\\\\')].
This has also been fixed. Note that it is
necessary to input "\\" if one is looking for a
backslash in db (as before).
A remark on the _formatAST function (py_utils.js):
We deescape only the chars `'`, `"`, and `\`
because it does not seem possible to produce a
string in the search view that would intend a
search for a line return or a tab for example.
A general remark:
Domains should always be in normalized form.
In that way they could be manipulated and combined
together without a tokenization/parsing!
closes odoo/odoo#31025
Diffstat (limited to 'addons/web/static/tests/core')
| -rw-r--r-- | addons/web/static/tests/core/py_utils_tests.js | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/addons/web/static/tests/core/py_utils_tests.js b/addons/web/static/tests/core/py_utils_tests.js index be5760fc6c7..fba8017cf01 100644 --- a/addons/web/static/tests/core/py_utils_tests.js +++ b/addons/web/static/tests/core/py_utils_tests.js @@ -1149,7 +1149,7 @@ QUnit.module('core', function () { assert.checkAST("1.4", "float value"); assert.checkAST("-12", "negative integer value"); assert.checkAST("True", "boolean"); - assert.checkAST("'some string'", "a string"); + assert.checkAST(`"some string"`, "a string"); assert.checkAST("None", "None"); }); @@ -1157,8 +1157,8 @@ QUnit.module('core', function () { assert.expect(3); assert.checkAST("{}", "empty dictionary"); - assert.checkAST("{'a': 1}", "dictionary with a single key"); - assert.checkAST("d['a']", "get a value in a dictionary"); + assert.checkAST(`{"a": 1}`, "dictionary with a single key"); + assert.checkAST(`d["a"]`, "get a value in a dictionary"); }); QUnit.test("list", function (assert) { @@ -1225,14 +1225,14 @@ QUnit.module('core', function () { QUnit.test("strftime", function (assert) { assert.expect(3); - assert.checkAST("time.strftime('%Y')", "strftime with year"); - assert.checkAST("time.strftime('%Y') + '-01-30'", "strftime with year"); - assert.checkAST("time.strftime('%Y-%m-%d %H:%M:%S')", "strftime with year"); + assert.checkAST(`time.strftime("%Y")`, "strftime with year"); + assert.checkAST(`time.strftime("%Y") + "-01-30"`, "strftime with year"); + assert.checkAST(`time.strftime("%Y-%m-%d %H:%M:%S")`, "strftime with year"); }); QUnit.test("context_today", function (assert) { assert.expect(1); - assert.checkAST("context_today().strftime('%Y-%m-%d')", "context today call"); + assert.checkAST(`context_today().strftime("%Y-%m-%d")`, "context today call"); }); @@ -1250,17 +1250,10 @@ QUnit.module('core', function () { assert.checkAST('(a - b).days', "substraction and .days"); assert.checkAST('a + day == date(2002, 3, 3)'); - var expr = "[('type', '=', 'in'), ('day', '<=', time.strftime('%Y-%m-%d')), ('day', '>', (context_today() - datetime.timedelta(days = 15)).strftime('%Y-%m-%d'))]"; + var expr = `[("type", "=", "in"), ("day", "<=", time.strftime("%Y-%m-%d")), ("day", ">", (context_today() - datetime.timedelta(days = 15)).strftime("%Y-%m-%d"))]`; assert.checkAST(expr); }); - QUnit.test("parse escaped quoted strings", function (assert) { - assert.expect(2); - - assert.checkAST(`'\"'`, "a string containing \""); - assert.checkAST(`'\'`, "a string containing \'"); - }); - QUnit.module('pyutils (_normalizeDomain)'); QUnit.assert.checkNormalization = function (domain, normalizedDomain) { @@ -1278,23 +1271,23 @@ QUnit.module('core', function () { assert.expect(3); assert.checkNormalization("[]"); - assert.checkNormalization("[('a', '=', 1)]"); - assert.checkNormalization("['!', ('a', '=', 1)]"); + assert.checkNormalization(`[("a", "=", 1)]`); + assert.checkNormalization(`["!", ("a", "=", 1)]`); }); QUnit.test("properly add the & in a non normalized domain", function (assert) { assert.expect(1); assert.checkNormalization( - "[('a', '=', 1), ('b', '=', 2)]", - "['&', ('a', '=', 1), ('b', '=', 2)]" + `[("a", "=", 1), ("b", "=", 2)]`, + `["&", ("a", "=", 1), ("b", "=", 2)]` ); }); QUnit.test("normalize domain with ! operator", function (assert) { assert.expect(1); assert.checkNormalization( - "['!', ('a', '=', 1), ('b', '=', 2)]", - "['&', '!', ('a', '=', 1), ('b', '=', 2)]" + `["!", ("a", "=", 1), ("b", "=", 2)]`, + `["&", "!", ("a", "=", 1), ("b", "=", 2)]` ); }); |
