-
Notifications
You must be signed in to change notification settings - Fork 10.5k
fix(find): respect spaces when query has no whitespace #20364
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
base: master
Are you sure you want to change the base?
fix(find): respect spaces when query has no whitespace #20364
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, it won't work with a pdf containing "Hello. World" and a query equals to "o. w" (fyi it's ok in Acrobat).
I think a fix could be to add optional white spaces around group of punctuation signs which induces to not have [ ]* between consecutive punctuation signs.
It'd lead to update SPECIAL_CHARS_REG_EXP but you've to take care to the case of . and ?.
|
Handled the Suggested test case. Also Attaching the PDF with the test case: |
| const DIACRITICS_REG_EXP = /\p{M}+/gu; | ||
| const SPECIAL_CHARS_REG_EXP = | ||
| /([.*+?^${}()|[\]\\])|(\p{P})|(\s+)|(\p{M})|(\p{L})/gu; | ||
| /([*+^${}()|[\]\\])|((?:[.?]|\p{P})+)|(\s+)|(\p{M})|(\p{L})/gu; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you want to not capture . or ? ?
| return `[ ]*\\${p1}[ ]*`; | ||
| // Escaped metacharacters like . * + ? ... | ||
| // Allow spaces around them ONLY if the user typed spaces. | ||
| return queryHasWhitespace ? `[ ]*\\${p1}[ ]*` : `\\${p1}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you want to do that ?
| return `[ ]*${p2}[ ]*`; | ||
| // Punctuation: allow optional spaces ONLY if the user typed spaces. | ||
| // p2 is a *run* of punctuation; escape it as a whole. | ||
| const escapedRun = escapeForRegex(p2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You just have to replace the . and the ? by . and ?
| // Punctuation: allow optional spaces ONLY if the user typed spaces. | ||
| // p2 is a *run* of punctuation; escape it as a whole. | ||
| const escapedRun = escapeForRegex(p2); | ||
| return queryHasWhitespace ? `[ ]*${escapedRun}[ ]*` : `${escapedRun}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again I don't understand why you want to make a difference between hasWhitespace and !hasWhitespace.
Fixes this issue:
#20225