From b412067b244c0152951726e4ff8bda2848e76e82 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Tue, 21 Dec 2021 16:56:28 +0000 Subject: [PATCH] Fix nulls leaking into geo urls (#7433) --- src/components/views/location/LocationPicker.tsx | 4 ++-- .../views/location/LocationPicker-test.tsx | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/components/views/location/LocationPicker.tsx b/src/components/views/location/LocationPicker.tsx index dc383d67a4..b00a6678bf 100644 --- a/src/components/views/location/LocationPicker.tsx +++ b/src/components/views/location/LocationPicker.tsx @@ -289,12 +289,12 @@ export function getGeoUri(position: GeolocationPosition): string { const lat = position.coords.latitude; const lon = position.coords.longitude; const alt = ( - position.coords.altitude !== undefined + Number.isFinite(position.coords.altitude) ? `,${position.coords.altitude}` : "" ); const acc = ( - position.coords.accuracy !== undefined + Number.isFinite(position.coords.accuracy) ? `;u=${ position.coords.accuracy }` : "" ); diff --git a/test/components/views/location/LocationPicker-test.tsx b/test/components/views/location/LocationPicker-test.tsx index 0d58612da6..e28c8cea78 100644 --- a/test/components/views/location/LocationPicker-test.tsx +++ b/test/components/views/location/LocationPicker-test.tsx @@ -35,6 +35,22 @@ describe("LocationPicker", () => { expect(getGeoUri(pos)).toEqual("geo:43.2,12.4"); }); + it("Nulls in location are not shown in URI", () => { + const pos: GeolocationPosition = { + coords: { + latitude: 43.2, + longitude: 12.4, + altitude: null, + accuracy: null, + altitudeAccuracy: null, + heading: null, + speed: null, + }, + timestamp: 12334, + }; + expect(getGeoUri(pos)).toEqual("geo:43.2,12.4"); + }); + it("Renders a URI with 3 coords", () => { const pos: GeolocationPosition = { coords: {