-
Notifications
You must be signed in to change notification settings - Fork 958
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
Add test for parsing brackets in range queries #13323
Conversation
d931c0d
to
58e70d6
Compare
Looking at the javacc file it seems range terms are parsed differently compared to normal tokens. This is strange but I bet there was a reason for it - now long forgotten. I think, logically, it should accept the same term notation that is used elsewhere. It will break backward compatibility but maybe consistency is worth this cost (for the major release)? |
I was thinking a fix like this could work: | <RANGE_GOOP: (~[ " ", "]", "}" ] | "\\ " | "\\]" | "\\}" )+ > simply allowing the range term to continue parsing through an escaped space or closing bracket. "Breaking" changes:
|
The joys of escaping... Never easy (hello, Windows command-line users...). You may want to add a randomized test that constructs those terms using a mix of characters and "allowed" escape sequences - a corner case will pop up quickly, I think. |
This PR has not had activity in the past 2 weeks, labeling it as stale. If the PR is waiting for review, notify the dev@lucene.apache.org list. Thank you for your contribution! |
Thanks for the advice @dweiss, I will play around with some test cases for this fix. In the meantime, I think we can merge this and I will open another PR with the grammar changes if I can get something working. |
Apologies for the delay, @benchaplin - I've merged this test into the main branch. |
Description
I've added some unit tests to protect/display the QueryParser's ability to parse brackets in range query terms when in quotes.
This issue raised a question about the QueryParser's ability to handle brackets in a range query's terms, even when escaped, for example:
You can get around this exception by wrapping each range query term in quotes:
This is because of this JavaCC grammar rule.
<RANGE_GOOP>
cannot handle a closing bracket, even an escaped one, while<RANGE_QUOTED>
can.I've added some unit tests to protect this functionality.
Any thoughts on whether
queryParser.parse( "[ a\\[i\\] TO b\\[i\\] ]" );
should work? I did play around with updating the grammar, it should be possible but I need to think more about how it might break backwards compatibility.