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

IndexError from NOT OR foobar #19

Open
CodeOptimist opened this issue Oct 5, 2021 · 0 comments
Open

IndexError from NOT OR foobar #19

CodeOptimist opened this issue Oct 5, 2021 · 0 comments

Comments

@CodeOptimist
Copy link

CodeOptimist commented Oct 5, 2021

A malformed query such as:

NOT OR foobar

throws IndexError: list index out of range in whoosh\qparser\syntax.py, line 376

class Wrapper(GroupNode):
    """Intermediate base class for nodes that wrap a single sub-node.
    """

    merging = False

    def query(self, parser):
        q = self.nodes[0].query(parser)  # <----- IndexError
        if q:
            return attach(self.qclass(q), self)

[<OP 'NOT'>, <OP 'OR'>, <None:'foobar'>] ➡️ [<NotGroup <OP 'OR'>>, <None:'foobar'>] ➡️ [<NotGroup >, <None:'foobar'>]

and <NotGroup > (no inner nodes) makes self.nodes[0] angry. 😄

Proposed fix:

    def query(self, parser):
        if self.nodes:  # <-----
            q = self.nodes[0].query(parser)
            if q:
                return attach(self.qclass(q), self)
@CodeOptimist CodeOptimist changed the title IndexError from "NOT OR foobar" IndexError from NOT OR foobar Dec 5, 2023
cclauss pushed a commit to cclauss/whoosh-1 that referenced this issue Jan 4, 2024
Add unit tests for 'jieba' dependency
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

1 participant