-
Notifications
You must be signed in to change notification settings - Fork 4
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
Enhance Search Query Handling with Special Characters #178
Conversation
Added lodash to the project dependencies and utilized its escapeRegExp function to escape special characters in the search query. This update is to ensure that when special characters are included in search terms, they are treated as literal characters in the regex used in the searchRegions function. These changes aim to prevent errors and crashes in the backend when users input special characters like '?' in the search field. Issue: #160 Signed-off-by: Nikolay Martyanov <ohmspectator@gmail.com>
WalkthroughThe update to Changes
Assessment against linked issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on X ? TipsChat with CodeRabbit Bot (
|
Apply Sweep Rules to your PR?
Type can be one of the following:
|
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.
Review Status
Actionable comments generated: 0
Configuration used: .coderabbit.yaml
Files ignored due to filter (1)
- backend/package.json
Files selected for processing (1)
- backend/src/controllers/regionController.js (2 hunks)
Additional comments: 4
backend/src/controllers/regionController.js (4)
4-4: The addition of lodash is correctly implemented to facilitate the escaping of regex special characters in search queries.
25-26: The implementation of
_.escapeRegExp
to escape special characters in search terms is correct and aligns with the PR's objective to enhance search functionality.33-36: The update to the
replacements
object to useescapedQueryTerms
for regex pattern construction is correct and ensures that special characters are properly escaped.42-45: The loop modification to iterate over
escapedQueryTerms
and the corresponding updates to theregexMatchCaseStatements
andsubstringMatchCaseStatements
are correctly implemented.
Description
This PR introduces an enhancement to the search functionality in the backend. By integrating lodash's
escapeRegExp
function, we now ensure that special characters in search terms are properly escaped, thereby avoiding errors and server crashes when users input characters like '?' in the search field. This update aims to improve the robustness and reliability of the search feature in our application.Related Issues
Closes: #160
How Was This Tested?
Tests were conducted with various search queries containing special characters, including but not limited to %, ', *, ?, and (. Each character was tested in isolation and in combination with alphanumeric characters to simulate real-world search queries. The tests were performed via the UI by inputting these characters into the search field. The backend handled all cases gracefully, properly escaping special characters and preventing any crashes or malformed SQL queries. No errors were encountered, and search functionality remained consistent and reliable across all tested scenarios.
Checklist
Before submitting your PR, please review the following:
Summary by CodeRabbit
Enhancements
New Features
Dependencies