Skip to content

fix: improve country name validation - #2405

Open
Nithya-3035 wants to merge 1 commit into
Canopus-Labs:mainfrom
Nithya-3035:patch-2
Open

Nithya-3035 wants to merge 1 commit into
Canopus-Labs:mainfrom
Nithya-3035:patch-2

Conversation

@Nithya-3035

Copy link
Copy Markdown

Updated backend/utils/nameCountry.js to improve country name validation and normalization.

  • Added Unicode normalization using normalize("NFKC").
  • Improved whitespace handling by trimming leading and trailing spaces.
  • Added support for multiple consecutive spaces.
  • Implemented case-insensitive country matching.
  • Used a Set for faster country lookup.
  • Added input type checking to reject non-string and empty values.
  • Exported the country list as a frozen array.
  • Preserved the existing isValidCountry function for compatibility.

These changes improve validation consistency, readability, and lookup performance.

📝 Pull Request Description

Related Issue

Closes #

Summary

Provide a short, reviewer-friendly summary of what changed and why.


Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature
  • ♻️ Refactoring
  • 📝 Documentation update
  • 🎨 UI/UX improvement
  • 🔥 Other(please describe) ______

How Has This Been Tested?

Describe the testing steps performed.


Screenshots (if applicable)

Add screenshots or videos to demonstrate the changes.


Checklist

  • My code follows the project's guidelines
  • I have tested my changes
  • I have updated documentation where necessary
  • I have linked the related issue
  • My changes do not introduce new warnings or errors

Updated `backend/utils/nameCountry.js` to improve country name validation and normalization.

- Added Unicode normalization using `normalize("NFKC")`.
- Improved whitespace handling by trimming leading and trailing spaces.
- Added support for multiple consecutive spaces.
- Implemented case-insensitive country matching.
- Used a `Set` for faster country lookup.
- Added input type checking to reject non-string and empty values.
- Exported the country list as a frozen array.
- Preserved the existing `isValidCountry` function for compatibility.

These changes improve validation consistency, readability, and lookup performance.
@coderabbitai

coderabbitai Bot commented Nov 12, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 46 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 40e7067e-c62a-4520-ada2-ed73f499e33a
Commits

Reviewing files that changed from the base of the PR and between a8d14cf and 4727d20.

Files selected for processing: 1

  • backend/utils/nameCountry.js
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

Copy link
Copy Markdown

Thank you for submitting your pull request, @Nithya-3035! 🙌
We'll review it as soon as possible.
If there are any specific instructions or feedback regarding your PR, we'll provide them here.
Thanks again for your contribution to our project! 😊

@Nithya-3035

Copy link
Copy Markdown
Author

Improved country name validation by adding Unicode normalization, whitespace handling, and case-insensitive matching. Also optimized country lookups using a Set and added input type validation to handle invalid values safely.

@github-actions github-actions Bot added the merge ready PR is mergeable and has no conflicts label Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge ready PR is mergeable and has no conflicts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant