gitfut icon indicating copy to clipboard operation
gitfut copied to clipboard

countryFromLocation() picks international city over US/Canada state — wrong flags for Cambridge, Paris, London, Rome, Dublin etc.

Open sanket1035 opened this issue 4 months ago • 1 comments

What happened

countryFromLocation() in lib/geo.ts gets the flag wrong for any US/Canada city that shares its name with a more "famous" international city. The function checks segments one at a time and returns on the first city match, without ever looking at the state/country that follows.

Examples (all currently wrong):

Location string Shows Should show
Cambridge, Massachusetts 🇬🇧 England 🇺🇸 US
Paris, Texas 🇫🇷 France 🇺🇸 US
London, Ontario 🇬🇧 England 🇨🇦 Canada
Rome, Georgia 🇮🇹 Italy 🇺🇸 US
Rome, New York 🇮🇹 Italy 🇺🇸 US
Dublin, Ohio 🇮🇪 Ireland 🇺🇸 US

This isn't rare — Cambridge, Paris, London, Rome, Dublin, and Athens are all common US/Canada town names picked by early settlers, so this will misflag a meaningful chunk of real profiles.

Steps to reproduce

  1. Set your GitHub profile location to Cambridge, Massachusetts (or any pair from the table above)
  2. Scout your own card on gitfut.com
  3. Flag shows England instead of US

Root cause

In countryFromLocation(), segments is looped and each segment is checked independently against COUNTRY / US_STATES / CITY — the function returns on the very first hit. For "Cambridge, Massachusetts", segment 1 is "cambridge", which exists in the CITY map only as the UK city → "eng" is returned immediately, before segment 2 ("massachusetts", a clear US state) is ever checked.

There's already a similar disambiguation pattern in the file for "georgia" (the pointsToUS() helper, lines 76-78) — country-vs-state ambiguity is checked against the other segments before deciding. The same idea just needs to extend to city name collisions: if a later segment in the same location string resolves to a US state (or another unambiguous US signal), a CITY match for a US-founded namesake town should win over the international city.

Suggested direction

Before returning on a CITY[seg] hit, check whether another segment in the same string points to a US state/alias (reusing or generalizing pointsToUS). If so, prefer "us" (or the matching state's country) over the international city's code. Could also invert the segment order — check state/country segments across the whole string first, then fall back to city matches only if nothing else resolved.

Environment

  • Browser: N/A (code-level bug, reproducible on any browser)
  • OS: N/A

sanket1035 avatar Jul 18 '26 20:07 sanket1035

@sanket1035 thanks for reporting this, unfortunately github does let you type anything in the localization form, making it hard to get correct countries

Younesfdj avatar Jul 18 '26 23:07 Younesfdj