diff --git a/.changeset/aa_fix_invalid_location_crash.md b/.changeset/aa_fix_invalid_location_crash.md new file mode 100644 index 00000000..4e6711ea --- /dev/null +++ b/.changeset/aa_fix_invalid_location_crash.md @@ -0,0 +1,5 @@ +--- +sable: patch +--- + +Fix crash when invalid location events are sent. diff --git a/src/app/components/message/MsgTypeRenderers.tsx b/src/app/components/message/MsgTypeRenderers.tsx index 66656f94..44b4b83c 100644 --- a/src/app/components/message/MsgTypeRenderers.tsx +++ b/src/app/components/message/MsgTypeRenderers.tsx @@ -462,7 +462,10 @@ type MLocationProps = { export function MLocation({ content }: MLocationProps) { const geoUri = content.geo_uri; if (typeof geoUri !== 'string') return ; + const location = parseGeoUri(geoUri); + if (!location) return ; + return ( {geoUri} diff --git a/src/app/utils/common.ts b/src/app/utils/common.ts index 678f1b6e..8507e06c 100644 --- a/src/app/utils/common.ts +++ b/src/app/utils/common.ts @@ -87,9 +87,17 @@ export const scaleYDimension = (x: number, scaledX: number, y: number): number = }; export const parseGeoUri = (location: string) => { + if (!location) return null; + const [, data] = location.split(':'); + if (!data) return null; + const [cords] = data.split(';'); + if (!cords) return null; + const [latitude, longitude] = cords.split(','); + if (!latitude || !longitude) return null; + return { latitude, longitude,