From 91bd8cb78d2e06703829cd9d23c1979c3dbd1368 Mon Sep 17 00:00:00 2001 From: sajeetharan Date: Fri, 14 Aug 2026 09:36:38 +0530 Subject: [PATCH] fix: normalize accented country searches --- components/SearchBar.jsx | 4 +++- lib/country.js | 5 ++++- tests/country.test.js | 9 +++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 tests/country.test.js diff --git a/components/SearchBar.jsx b/components/SearchBar.jsx index d8fa13e..6ecffd1 100644 --- a/components/SearchBar.jsx +++ b/components/SearchBar.jsx @@ -2,6 +2,7 @@ import React, { useState, useRef, useCallback } from 'react'; import SpecialTags from './SpecialTags.jsx'; +import { countryKey } from '../lib/country.js'; const SAMPLES_BY_MODE = { text: [ @@ -45,10 +46,11 @@ export default function SearchBar({ developers, onResults, onReset, onGenerateCa if (m === 'text') { const lower = q.trim().toLowerCase(); + const locationKey = countryKey(q.trim()); let results = developers.filter(d => (d.login && d.login.toLowerCase().includes(lower)) || (d.name && d.name.toLowerCase().includes(lower)) || - (d.location && d.location.toLowerCase().includes(lower)) + (d.location && countryKey(d.location).includes(locationKey)) ); if (results.length === 0) { diff --git a/lib/country.js b/lib/country.js index 1aee537..a47b730 100644 --- a/lib/country.js +++ b/lib/country.js @@ -72,7 +72,10 @@ export function normalizeCountry(name) { // Comparable form — use whenever two country names from different sources are matched export function countryKey(name) { - return normalizeCountry(name).toLowerCase(); + return normalizeCountry(name) + .normalize('NFD') + .replace(/[\u0300-\u036f]/g, '') + .toLowerCase(); } export function normalizeCity(name) { diff --git a/tests/country.test.js b/tests/country.test.js new file mode 100644 index 0000000..2656bd2 --- /dev/null +++ b/tests/country.test.js @@ -0,0 +1,9 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { countryKey, extractCountry } from '../lib/country.js'; + +test('countryKey matches accented country names to unaccented map names', () => { + assert.equal(countryKey(extractCountry('Perú')), countryKey('Peru')); + assert.equal(countryKey('España'), countryKey('Espana')); + assert.ok(countryKey('Lima, Perú').includes(countryKey('Peru'))); +}); \ No newline at end of file