changeset 8e38c5eebb96 in sao:default
details: https://hg.tryton.org/sao?cmd=changeset&node=8e38c5eebb96
description:
        Test for sub-domain instead of not leaf in domain parser

        issue11472
        review411171004
diffstat:

 src/common.js |  26 ++++++++++++--------------
 tests/sao.js  |   1 +
 2 files changed, 13 insertions(+), 14 deletions(-)

diffs (78 lines):

diff -r 20ffa54f8b23 -r 8e38c5eebb96 src/common.js
--- a/src/common.js     Wed May 11 23:19:28 2022 +0200
+++ b/src/common.js     Thu May 19 21:54:36 2022 +0200
@@ -1442,15 +1442,15 @@
             }
             return results;
         },
-        is_leaf: function(element) {
-            return ((element instanceof Array) && element.clause);
+        is_subdomain: function(element) {
+            return (element instanceof Array) && !element.clause;
         },
         ending_clause: function(domain, depth=0) {
             if (domain.length === 0) {
                 return [null, depth];
             }
             var last_element = domain[domain.length - 1];
-            if (!this.is_leaf(last_element)) {
+            if (this.is_subdomain(last_element)) {
                 return this.ending_clause(last_element, depth + 1);
             }
             return [last_element, depth];
@@ -1461,7 +1461,7 @@
             for (i = 0, len=domain.length - 1; i < len; i++) {
                 results.push(domain[i]);
             }
-            if (!this.is_leaf(domain[i])) {
+            if (this.is_subdomain(domain[i])) {
                 results = results.concat(this.replace_ending_clause(domain[i],
                             clause));
             } else {
@@ -1475,7 +1475,7 @@
             }
             var results = domain.slice(0, -1);
             var last_element = domain[domain.length - 1];
-            if (!this.is_leaf(last_element)) {
+            if (this.is_subdomain(last_element)) {
                 results.push(this.append_ending_clause(last_element, clause,
                             depth - 1));
             } else {
@@ -2200,19 +2200,17 @@
             }
         },
         simplify: function(value) {
-            if ((value instanceof Array) && !this.is_leaf(value)) {
-                if ((value.length == 1) && (value[0] instanceof Array) &&
-                        ((value[0][0] == 'AND') || (value[0][0] == 'OR') ||
-                         (value[0][0] instanceof Array))) {
+            if (this.is_subdomain(value)) {
+                if ((value.length == 1) && this.is_subdomain(value[0])) {
                     return this.simplify(value[0]);
                 } else if ((value.length == 2) &&
-                        ((value[0] == 'AND') || (value[0] == 'OR')) &&
-                        (value[1] instanceof Array)) {
+                    ((value[0] == 'AND') || (value[0] == 'OR')) &&
+                    this.is_subdomain(value[1])) {
                     return this.simplify(value[1]);
                 } else if ((value.length == 3) &&
-                        ((value[0] == 'AND') || (value[0] == 'OR')) &&
-                        (value[1] instanceof Array) &&
-                        (value[0] == value[1][0])) {
+                    ((value[0] == 'AND') || (value[0] == 'OR')) &&
+                    this.is_subdomain(value[1]) &&
+                    (value[0] == value[1][0])) {
                     value = this.simplify(value[1]).concat([value[2]]);
                 }
                 return value.map(v => this.simplify(v));
diff -r 20ffa54f8b23 -r 8e38c5eebb96 tests/sao.js
--- a/tests/sao.js      Wed May 11 23:19:28 2022 +0200
+++ b/tests/sao.js      Thu May 19 21:54:36 2022 +0200
@@ -3050,6 +3050,7 @@
         ['Name: !=foo', []],
         ['', ["Name: "]],
         [' ', ["", "Name: "]],
+        ["Name: foo or", ["Name: foo"]],
         ].forEach(function(test) {
             var value = test[0];
             var expected = test[1];

Reply via email to