Extra white space cause maximum stack error
Opened this issue · 2 comments
paulck commented
Hi,
if you invoke the parser with string '(a AND b) OR c' will work but with ' (a AND b) OR c' it will end with :
Unhandled rejection RangeError: Maximum call stack size exceeded
riichard commented
Thanks, I'll look into it :)
vchapple17 commented
For those who are looking, I found a quick fix (for my issue at least).
I recursion comes when the andQuery
is split is not successfully split into parts and the parseBooleanQuery is called multiple times on the same string. The solution below checks that if the andQuery
is the same as the first and only index of ands
array, it just returns that string.
Hope it helps others get a jump on solving it for their own unique cases.
function parseBooleanQuery(searchPhrase) {
//...
if (ands.length === 1 && ands[0] === andQuery) {
andPath.push(andQuery);
}
else {
// Iterate through all the strings from the AND query
for (var i = 0; i < ands.length; i++) {
// If the string contains brackets, parse it recursively, and add it to
// `nestedPaths`.
if (containsBrackets(ands[i])) {
nestedPaths.push(parseBooleanQuery(ands[i]));
}
// If it doesn't. Push the word to `andPath`.
else {
andPath.push(ands[i]);
}
}
}
// ...