From 5e1a18137ba676e8ee49f5c7595a99ce4c21a56f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20Gaudencio=20do=20R=C3=AAgo?= Date: Mon, 16 Dec 2024 19:27:51 -0300 Subject: [PATCH 1/2] Fix location misencoded string --- website/matchers/location.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/website/matchers/location.ts b/website/matchers/location.ts index 7f5bac86b..c0461dd34 100644 --- a/website/matchers/location.ts +++ b/website/matchers/location.ts @@ -81,14 +81,25 @@ const matchLocation = result &&= !target.country || target.country === source.country; return result; }; + +function fixEncoding(input: string): string { + // Interpret the misencoded string as Latin-1 (cf-headers), then decode it as UTF-8 + try { + const latin1Bytes = [...input].map((char) => char.charCodeAt(0)); + return new TextDecoder("utf-8").decode(Uint8Array.from(latin1Bytes)); + } catch (_) { + return input; + } +} + const escaped = ( { city, country, regionCode, coordinates }: MapLocation, ): MapLocation => { return { coordinates, regionCode, - city: city ? decodeURIComponent(escape(city)) : city, - country: country ? decodeURIComponent(escape(country)) : country, + city: city ? fixEncoding(city) : city, + country: country ? fixEncoding(country) : country, }; }; /** @@ -118,4 +129,4 @@ export default function MatchLocation( } return (includeLocations?.some(matchLocation(true, escaped(userLocation))) ?? true); -} +} \ No newline at end of file From 8ad26a5207d29a2fd32d0f28cbe42dfc0e4f900a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20Gaudencio=20do=20R=C3=AAgo?= Date: Mon, 16 Dec 2024 19:28:28 -0300 Subject: [PATCH 2/2] Fix location misencoded string --- website/matchers/location.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/matchers/location.ts b/website/matchers/location.ts index c0461dd34..8f6e2033a 100644 --- a/website/matchers/location.ts +++ b/website/matchers/location.ts @@ -129,4 +129,4 @@ export default function MatchLocation( } return (includeLocations?.some(matchLocation(true, escaped(userLocation))) ?? true); -} \ No newline at end of file +}