Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra white space cause maximum stack error #11

Open
paulck opened this issue Mar 14, 2018 · 2 comments
Open

Extra white space cause maximum stack error #11

paulck opened this issue Mar 14, 2018 · 2 comments

Comments

@paulck
Copy link

paulck commented Mar 14, 2018

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
Copy link
Owner

Thanks, I'll look into it :)

@vchapple17
Copy link

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]);
        }
      }
    }

     // ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants