Preserve query in geo URI
[zxing.git] / core / src / com / google / zxing / client / result / GeoResultParser.java
index b4a0325..8459ddc 100644 (file)
@@ -19,7 +19,7 @@ package com.google.zxing.client.result;
 import com.google.zxing.Result;
 
 /**
- * Parses a "geo:" URI result, which specifices a location on the surface of
+ * Parses a "geo:" URI result, which specifies a location on the surface of
  * the Earth as well as an optional altitude above the surface. See
  * <a href="http://tools.ietf.org/html/draft-mayrhofer-geo-uri-00">
  * http://tools.ietf.org/html/draft-mayrhofer-geo-uri-00</a>.
@@ -38,10 +38,13 @@ final class GeoResultParser extends ResultParser {
     }
     // Drop geo, query portion
     int queryStart = rawText.indexOf('?', 4);
+    String query;
     String geoURIWithoutQuery;
     if (queryStart < 0) {
+      query = null;
       geoURIWithoutQuery = rawText.substring(4);
     } else {
+      query = rawText.substring(queryStart + 1);
       geoURIWithoutQuery = rawText.substring(4, queryStart);
     }
     int latitudeEnd = geoURIWithoutQuery.indexOf(',');
@@ -52,6 +55,9 @@ final class GeoResultParser extends ResultParser {
     double latitude, longitude, altitude;
     try {
       latitude = Double.parseDouble(geoURIWithoutQuery.substring(0, latitudeEnd));
+      if (latitude > 90.0 || latitude < -90.0) {
+        return null;
+      }
       if (longitudeEnd < 0) {
         longitude = Double.parseDouble(geoURIWithoutQuery.substring(latitudeEnd + 1));
         altitude = 0.0;
@@ -59,10 +65,13 @@ final class GeoResultParser extends ResultParser {
         longitude = Double.parseDouble(geoURIWithoutQuery.substring(latitudeEnd + 1, longitudeEnd));
         altitude = Double.parseDouble(geoURIWithoutQuery.substring(longitudeEnd + 1));
       }
+      if (longitude > 180.0 || longitude < -180.0 || altitude < 0) {
+        return null;
+      }
     } catch (NumberFormatException nfe) {
       return null;
     }
-    return new GeoParsedResult(rawText, latitude, longitude, altitude);
+    return new GeoParsedResult(latitude, longitude, altitude, query);
   }
 
 }
\ No newline at end of file