Merge "Correct range checking for location strings during conversion"
diff --git a/location/java/android/location/Location.java b/location/java/android/location/Location.java
index bf3387b..bca9be6 100644
--- a/location/java/android/location/Location.java
+++ b/location/java/android/location/Location.java
@@ -257,11 +257,13 @@
int deg = Integer.parseInt(degrees);
double min;
double sec = 0.0;
+ boolean secPresent = false;
if (st.hasMoreTokens()) {
min = Integer.parseInt(minutes);
String seconds = st.nextToken();
sec = Double.parseDouble(seconds);
+ secPresent = true;
} else {
min = Double.parseDouble(minutes);
}
@@ -273,11 +275,15 @@
if ((deg < 0.0) || (deg > 179 && !isNegative180)) {
throw new IllegalArgumentException("coordinate=" + coordinate);
}
- if (min < 0 || min > 59) {
+
+ // min must be in [0, 59] if seconds are present, otherwise [0.0, 60.0)
+ if (min < 0 || min >= 60 || (secPresent && (min > 59))) {
throw new IllegalArgumentException("coordinate=" +
coordinate);
}
- if (sec < 0 || sec > 59) {
+
+ // sec must be in [0.0, 60.0)
+ if (sec < 0 || sec >= 60) {
throw new IllegalArgumentException("coordinate=" +
coordinate);
}