uncovering-world / track-your-regions

Track Your Regions: a web tool for travellers to discover and track areas of interest. Work In Progress...
http://uncovering.world
Apache License 2.0
3 stars 4 forks source link

Enhance Search Query Handling with Special Characters #178

Closed OhmSpectator closed 11 months ago

OhmSpectator commented 11 months ago

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

coderabbitai[bot] commented 11 months ago

Walkthrough

The update to regionController.js addresses a crash issue when special characters, like a URL-encoded '?', are included in search queries. By incorporating lodash to escape regex patterns, the code now safely handles special characters in search terms, mitigating potential crashes and security vulnerabilities related to SQL query execution.

Changes

File Path Change Summary
.../src/controllers/regionController.js Added lodash dependency and updated searchRegions function to escape regex patterns for search queries.

Assessment against linked issues

Objective Addressed Explanation
Prevent backend crash with special characters in search queries (#160)
Correct handling of URL-encoded characters to prevent crashes (#160)
Address SQL query invalid regex errors with special characters (#160)
Sanitize URL-encoded characters in query parameters for security (#160)
Modify SQL query construction to prevent regex errors (#160)

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 ?


Tips ### Chat with CodeRabbit Bot (`@coderabbitai`) - You can directly reply to a review comment made by CodeRabbit. Example: - _I pushed a fix in commit ``._ - You can tag CodeRabbit on specific lines of code or entire files in the PR by tagging `@coderabbitai` in a comment. Examples: - _@coderabbitai generate unit tests for this file_ - _@coderabbitai modularize this function_ - You can tag `@coderabbitai` in a PR comment and ask questions about the PR and the codebase. Use quoted replies to pass the context for follow-up questions. Examples: - _@coderabbitai render interesting statistics about this repository as a table_. - _@coderabbitai show all the `console.log` statements in this repository_. - _@coderabbitai generate unit tests for the `src/utils.ts` file_. ### CodeRabbit Commands (invoked as PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger a review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - The JSON schema for the configuration file is available [here](https://coderabbit.ai/integrations/coderabbit-overrides.v2.json). - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json` ### CodeRabbit Discord Community Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback.
sweep-ai[bot] commented 11 months ago

Apply Sweep Rules to your PR?

[Issue: #] ``` Type can be one of the following: - `front`: Frontend - `back`: Backend - `deploy`: Deployment Or leave it blank if the commit is not specific to any of the above. Ensure the commit message is concise yet descriptive. If the commit fixes an issue, add the issue number in the commit message.