Bug 1239823 - Part 2: sanitise input dates for DatePicker r=margaret draft
authorAndrzej Hunt <ahunt@mozilla.com>
Wed, 03 Feb 2016 15:23:09 -0800
changeset 330182 8a9182bb3337fea8720dc6a08afa325333e50c7d
parent 330181 237b6738ff4323b4adc81926759d9118725507d6
child 514121 363584f1b9d2f059b44f3ff7f7fdb4327724008c
push id10701
push userahunt@mozilla.com
push dateWed, 10 Feb 2016 22:45:06 +0000
reviewersmargaret
bugs1239823
milestone47.0a1
Bug 1239823 - Part 2: sanitise input dates for DatePicker r=margaret MozReview-Commit-ID: GiXgQwscGPT
mobile/android/base/java/org/mozilla/gecko/widget/DateTimePicker.java
--- a/mobile/android/base/java/org/mozilla/gecko/widget/DateTimePicker.java
+++ b/mobile/android/base/java/org/mozilla/gecko/widget/DateTimePicker.java
@@ -299,16 +299,32 @@ public class DateTimePicker extends Fram
             } else {
                 mTempDate.setTimeInMillis(System.currentTimeMillis());
             }
         } catch (Exception ex) {
             Log.e(LOGTAG, "Error parsing format string: " + ex);
             mTempDate.setTimeInMillis(System.currentTimeMillis());
         }
 
+        if (mMaxDate.before(mMinDate)) {
+            // If the input date range is illogical/garbage, we should not restrict the input range (i.e. allow the
+            // user to select any date). If we try to make any assumptions based on the illogical min/max date we could
+            // potentially prevent the user from selecting dates that are in the developers intended range, so it's best
+            // to allow anything.
+            mMinDate.set(DEFAULT_START_YEAR, Calendar.JANUARY, 1);
+            mMaxDate.set(DEFAULT_END_YEAR, Calendar.DECEMBER, 31);
+        }
+
+        // mTempDate will either be a site-supplied value, or today's date otherwise. CalendarView implementations can
+        // crash if they're supplied an invalid date (i.e. a date not in the specified range), hence we need to set
+        // a sensible default date here.
+        if (mTempDate.before(mMinDate) || mTempDate.after(mMaxDate)) {
+            mTempDate.setTimeInMillis(mMinDate.getTimeInMillis());
+        }
+
         // If we're displaying a date, the screen is wide enough
         // (and if we're using an SDK where the calendar view exists)
         // then display a calendar.
         if (Versions.feature11Plus &&
             (mState == PickersState.DATE || mState == PickersState.DATETIME) &&
             mScreenWidth >= SCREEN_SIZE_THRESHOLD) {
 
             if (DEBUG) {