Merge pull request #263 from 7w1/location-patch
fix crash when invalid location sent
This commit is contained in:
3 files changed
+16
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
sable: patch
|
||||
---
|
||||
|
||||
Fix crash when invalid location events are sent.
|
||||
@@ -462,7 +462,10 @@ type MLocationProps = {
|
||||
export function MLocation({ content }: MLocationProps) {
|
||||
const geoUri = content.geo_uri;
|
||||
if (typeof geoUri !== 'string') return <BrokenContent />;
|
||||
|
||||
const location = parseGeoUri(geoUri);
|
||||
if (!location) return <BrokenContent />;
|
||||
|
||||
return (
|
||||
<Box direction="Column" alignItems="Start" gap="100">
|
||||
<Text size="T400">{geoUri}</Text>
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user