Fix nulls leaking into geo urls (#7433)
This commit is contained in:
parent
d4bafdcddd
commit
b412067b24
2 changed files with 18 additions and 2 deletions
|
@ -289,12 +289,12 @@ export function getGeoUri(position: GeolocationPosition): string {
|
||||||
const lat = position.coords.latitude;
|
const lat = position.coords.latitude;
|
||||||
const lon = position.coords.longitude;
|
const lon = position.coords.longitude;
|
||||||
const alt = (
|
const alt = (
|
||||||
position.coords.altitude !== undefined
|
Number.isFinite(position.coords.altitude)
|
||||||
? `,${position.coords.altitude}`
|
? `,${position.coords.altitude}`
|
||||||
: ""
|
: ""
|
||||||
);
|
);
|
||||||
const acc = (
|
const acc = (
|
||||||
position.coords.accuracy !== undefined
|
Number.isFinite(position.coords.accuracy)
|
||||||
? `;u=${ position.coords.accuracy }`
|
? `;u=${ position.coords.accuracy }`
|
||||||
: ""
|
: ""
|
||||||
);
|
);
|
||||||
|
|
|
@ -35,6 +35,22 @@ describe("LocationPicker", () => {
|
||||||
expect(getGeoUri(pos)).toEqual("geo:43.2,12.4");
|
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", () => {
|
it("Renders a URI with 3 coords", () => {
|
||||||
const pos: GeolocationPosition = {
|
const pos: GeolocationPosition = {
|
||||||
coords: {
|
coords: {
|
||||||
|
|
Loading…
Reference in a new issue