changeset 45e2c8de9e20 in sao:6.2
details: https://hg.tryton.org/sao?cmd=changeset&node=45e2c8de9e20
description:
Test for sub-domain instead of not leaf in domain parser
issue11472
review411171004
(grafted from 8e38c5eebb969c9b999876225df3f21df17572b3)
diffstat:
src/common.js | 26 ++++++++++++--------------
tests/sao.js | 1 +
2 files changed, 13 insertions(+), 14 deletions(-)
diffs (79 lines):
diff -r 29ec60559d15 -r 45e2c8de9e20 src/common.js
--- a/src/common.js Mon Apr 25 18:08:58 2022 +0200
+++ b/src/common.js Thu May 19 21:54:36 2022 +0200
@@ -1422,8 +1422,8 @@
}
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) {
if (depth === undefined) {
@@ -1433,7 +1433,7 @@
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];
@@ -1444,7 +1444,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 {
@@ -1458,7 +1458,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 {
@@ -2199,19 +2199,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(this.simplify.bind(this));
diff -r 29ec60559d15 -r 45e2c8de9e20 tests/sao.js
--- a/tests/sao.js Mon Apr 25 18:08:58 2022 +0200
+++ b/tests/sao.js Thu May 19 21:54:36 2022 +0200
@@ -3002,6 +3002,7 @@
['Name: !=foo', []],
['', ["Name: "]],
[' ', ["", "Name: "]],
+ ["Name: foo or", ["Name: foo"]],
].forEach(function(test) {
var value = test[0];
var expected = test[1];