forked from github/cinny
Fix crash with bad location uri (#2746)
fix crash with bad location uri
This commit is contained in:
@@ -389,6 +389,8 @@ 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,13 +87,21 @@ export const scaleYDimension = (x: number, scaledX: number, y: number): number =
|
||||
};
|
||||
|
||||
export const parseGeoUri = (location: string) => {
|
||||
const [, data] = location.split(':');
|
||||
const [cords] = data.split(';');
|
||||
const [latitude, longitude] = cords.split(',');
|
||||
return {
|
||||
latitude,
|
||||
longitude,
|
||||
};
|
||||
try {
|
||||
const [, data] = location.split(':');
|
||||
const [cords] = data.split(';');
|
||||
const [latitude, longitude] = cords.split(',');
|
||||
|
||||
if (typeof latitude === 'string' && typeof longitude === 'string') {
|
||||
return {
|
||||
latitude,
|
||||
longitude,
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
const START_SLASHES_REG = /^\/+/g;
|
||||
|
||||
Reference in New Issue
Block a user