From fcf3b8657a74c573447cda86cf3104826e36fd4a Mon Sep 17 00:00:00 2001 From: Andrzej Hunt Date: Wed, 3 Feb 2016 15:23:09 -0800 Subject: [PATCH] Bug 1239823 - Part 2: sanitise input dates for DatePicker r=margaret MozReview-Commit-ID: GiXgQwscGPT --- .../org/mozilla/gecko/widget/DateTimePicker.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/mobile/android/base/java/org/mozilla/gecko/widget/DateTimePicker.java b/mobile/android/base/java/org/mozilla/gecko/widget/DateTimePicker.java index 84ad86cb76d..2e6bd6cc23f 100644 --- a/mobile/android/base/java/org/mozilla/gecko/widget/DateTimePicker.java +++ b/mobile/android/base/java/org/mozilla/gecko/widget/DateTimePicker.java @@ -304,6 +304,22 @@ public class DateTimePicker extends FrameLayout { 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.