Browse Source

fix(birthplace): restore strict deterministic city and country parsing without swapping

master
mortezaei 3 days ago
parent
commit
38953095a9
  1. 37
      src/components/Componentes/question-birthplace.tsx

37
src/components/Componentes/question-birthplace.tsx

@ -65,30 +65,23 @@ function parseValue(rawValue: unknown): { country: string; city: string } {
"ایالات متحده آمریکا (US)",
);
let parts: string[] = [];
if (str.includes(",")) {
parts = str.split(",").map((s) => s.trim());
} else if (str.includes("،")) {
parts = str.split("،").map((s) => s.trim());
} else if (str.includes(" - ")) {
parts = str.split(" - ").map((s) => s.trim());
const idx = str.lastIndexOf(",");
const cityPart = str.slice(0, idx).trim();
const countryPart = str.slice(idx + 1).trim();
return { city: cityPart, country: countryPart };
}
if (parts.length >= 2) {
const part0 = parts[0] || "";
const part1 = parts.slice(1).join(", ").trim();
const isPart0Country = isKnownCountry(part0);
const isPart1Country = isKnownCountry(part1);
if (isPart0Country && !isPart1Country) {
return { country: part0, city: part1 };
}
if (isPart1Country && !isPart0Country) {
return { country: part1, city: part0 };
}
// Default standard order: City first, Country second
return { city: part0, country: part1 };
if (str.includes("،")) {
const idx = str.lastIndexOf("،");
const cityPart = str.slice(0, idx).trim();
const countryPart = str.slice(idx + 1).trim();
return { city: cityPart, country: countryPart };
}
if (str.includes(" - ")) {
const idx = str.lastIndexOf(" - ");
const cityPart = str.slice(0, idx).trim();
const countryPart = str.slice(idx + 3).trim();
return { city: cityPart, country: countryPart };
}
if (isKnownCountry(str)) {

Loading…
Cancel
Save