Avoid NaNs in parseGeoUri return (#7396)
This commit is contained in:
parent
818465a4d6
commit
144e4c61fc
2 changed files with 20 additions and 11 deletions
|
@ -97,6 +97,15 @@ export default class MLocationBody extends React.Component<IBodyProps, IState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseGeoUri(uri: string): GeolocationCoordinates {
|
export function parseGeoUri(uri: string): GeolocationCoordinates {
|
||||||
|
function parse(s: string): number {
|
||||||
|
const ret = parseFloat(s);
|
||||||
|
if (Number.isNaN(ret)) {
|
||||||
|
return undefined;
|
||||||
|
} else {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const m = uri.match(/^\s*geo:(.*?)\s*$/);
|
const m = uri.match(/^\s*geo:(.*?)\s*$/);
|
||||||
if (!m) return;
|
if (!m) return;
|
||||||
const parts = m[1].split(';');
|
const parts = m[1].split(';');
|
||||||
|
@ -104,12 +113,12 @@ export function parseGeoUri(uri: string): GeolocationCoordinates {
|
||||||
let uncertainty: number;
|
let uncertainty: number;
|
||||||
for (const param of parts.slice(1)) {
|
for (const param of parts.slice(1)) {
|
||||||
const m = param.match(/u=(.*)/);
|
const m = param.match(/u=(.*)/);
|
||||||
if (m) uncertainty = parseFloat(m[1]);
|
if (m) uncertainty = parse(m[1]);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
latitude: parseFloat(coords[0]),
|
latitude: parse(coords[0]),
|
||||||
longitude: parseFloat(coords[1]),
|
longitude: parse(coords[1]),
|
||||||
altitude: parseFloat(coords[2]),
|
altitude: parse(coords[2]),
|
||||||
accuracy: uncertainty,
|
accuracy: uncertainty,
|
||||||
altitudeAccuracy: undefined,
|
altitudeAccuracy: undefined,
|
||||||
heading: undefined,
|
heading: undefined,
|
||||||
|
|
|
@ -52,7 +52,7 @@ describe("MLocationBody", () => {
|
||||||
{
|
{
|
||||||
latitude: 48.198634,
|
latitude: 48.198634,
|
||||||
longitude: 16.371648,
|
longitude: 16.371648,
|
||||||
altitude: NaN, // TODO: should be undefined
|
altitude: undefined,
|
||||||
accuracy: 40,
|
accuracy: 40,
|
||||||
altitudeAccuracy: undefined,
|
altitudeAccuracy: undefined,
|
||||||
heading: undefined,
|
heading: undefined,
|
||||||
|
@ -66,7 +66,7 @@ describe("MLocationBody", () => {
|
||||||
{
|
{
|
||||||
latitude: 90,
|
latitude: 90,
|
||||||
longitude: -22.43,
|
longitude: -22.43,
|
||||||
altitude: NaN, // TODO: should be undefined
|
altitude: undefined,
|
||||||
accuracy: undefined,
|
accuracy: undefined,
|
||||||
altitudeAccuracy: undefined,
|
altitudeAccuracy: undefined,
|
||||||
heading: undefined,
|
heading: undefined,
|
||||||
|
@ -80,7 +80,7 @@ describe("MLocationBody", () => {
|
||||||
{
|
{
|
||||||
latitude: 90,
|
latitude: 90,
|
||||||
longitude: 46,
|
longitude: 46,
|
||||||
altitude: NaN, // TODO: should be undefined
|
altitude: undefined,
|
||||||
accuracy: undefined,
|
accuracy: undefined,
|
||||||
altitudeAccuracy: undefined,
|
altitudeAccuracy: undefined,
|
||||||
heading: undefined,
|
heading: undefined,
|
||||||
|
@ -94,7 +94,7 @@ describe("MLocationBody", () => {
|
||||||
{
|
{
|
||||||
latitude: 66,
|
latitude: 66,
|
||||||
longitude: 30,
|
longitude: 30,
|
||||||
altitude: NaN, // TODO: should be undefined
|
altitude: undefined,
|
||||||
accuracy: 6.500,
|
accuracy: 6.500,
|
||||||
altitudeAccuracy: undefined,
|
altitudeAccuracy: undefined,
|
||||||
heading: undefined,
|
heading: undefined,
|
||||||
|
@ -108,7 +108,7 @@ describe("MLocationBody", () => {
|
||||||
{
|
{
|
||||||
latitude: 66.0,
|
latitude: 66.0,
|
||||||
longitude: 30,
|
longitude: 30,
|
||||||
altitude: NaN, // TODO: should be undefined
|
altitude: undefined,
|
||||||
accuracy: 6.5,
|
accuracy: 6.5,
|
||||||
altitudeAccuracy: undefined,
|
altitudeAccuracy: undefined,
|
||||||
heading: undefined,
|
heading: undefined,
|
||||||
|
@ -122,7 +122,7 @@ describe("MLocationBody", () => {
|
||||||
{
|
{
|
||||||
latitude: 70,
|
latitude: 70,
|
||||||
longitude: 20,
|
longitude: 20,
|
||||||
altitude: NaN, // TODO: should be undefined
|
altitude: undefined,
|
||||||
accuracy: undefined,
|
accuracy: undefined,
|
||||||
altitudeAccuracy: undefined,
|
altitudeAccuracy: undefined,
|
||||||
heading: undefined,
|
heading: undefined,
|
||||||
|
@ -136,7 +136,7 @@ describe("MLocationBody", () => {
|
||||||
{
|
{
|
||||||
latitude: -7.5,
|
latitude: -7.5,
|
||||||
longitude: 20,
|
longitude: 20,
|
||||||
altitude: NaN, // TODO: should be undefined
|
altitude: undefined,
|
||||||
accuracy: undefined,
|
accuracy: undefined,
|
||||||
altitudeAccuracy: undefined,
|
altitudeAccuracy: undefined,
|
||||||
heading: undefined,
|
heading: undefined,
|
||||||
|
|
Loading…
Reference in a new issue