summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/core
diff options
context:
space:
mode:
authorMathieu Duckerts-Antoine <dam@odoo.com>2018-12-26 16:01:18 +0000
committerMathieu Duckerts-Antoine <dam@odoo.com>2019-02-12 12:45:51 +0000
commit01c159fd9fefd9863d2eed5a1f75f709595de294 (patch)
tree1a3c6cf5fe68a46c584c487d6ed48c2dcb7fccdd /addons/web/static/tests/core
parent6d5a993cf74173456734cccd2ea2c13027c04bbd (diff)
[FIX] web: quotes and backslashes in search view
The commit 6d3ada178f7caf6ea159b871648ca4c440c7845b 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#29756
Diffstat (limited to 'addons/web/static/tests/core')
-rw-r--r--addons/web/static/tests/core/py_utils_tests.js35
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)]`
);
});