aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Chan <mchan@android.com>2012-01-05 12:09:19 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2012-01-05 12:09:19 -0800
commit5042db7dbb7d4c932392c6e28f7a4d32af8fd264 (patch)
treea8d5d4bb703d6ca16afc934a0d7e4f5735b65c99
parentf68a5e7f1608c46bb19520bd74ea7a1a75bf075e (diff)
parentb9a152ecd47d1b26f045e1cdef1ab40e36a63999 (diff)
downloadcalendar-5042db7dbb7d4c932392c6e28f7a4d32af8fd264.tar.gz
am b9a152ec: am 0335d9f5: Fix rrules with bad count and interval during parsing
* commit 'b9a152ecd47d1b26f045e1cdef1ab40e36a63999': Fix rrules with bad count and interval during parsing
-rw-r--r--src/com/android/calendarcommon/EventRecurrence.java12
-rw-r--r--tests/src/com/android/calendarcommon/EventRecurrenceTest.java129
2 files changed, 139 insertions, 2 deletions
diff --git a/src/com/android/calendarcommon/EventRecurrence.java b/src/com/android/calendarcommon/EventRecurrence.java
index b179071..ca91817 100644
--- a/src/com/android/calendarcommon/EventRecurrence.java
+++ b/src/com/android/calendarcommon/EventRecurrence.java
@@ -747,14 +747,22 @@ public class EventRecurrence {
/** parses COUNT=[non-negative-integer] */
private static class ParseCount extends PartParser {
@Override public int parsePart(String value, EventRecurrence er) {
- er.count = parseIntRange(value, 0, Integer.MAX_VALUE, true);
+ er.count = parseIntRange(value, Integer.MIN_VALUE, Integer.MAX_VALUE, true);
+ if (er.count < 0) {
+ Log.d(TAG, "Invalid Count. Forcing COUNT to 1 from " + value);
+ er.count = 1; // invalid count. assume one time recurrence.
+ }
return PARSED_COUNT;
}
}
/** parses INTERVAL=[non-negative-integer] */
private static class ParseInterval extends PartParser {
@Override public int parsePart(String value, EventRecurrence er) {
- er.interval = parseIntRange(value, 1, Integer.MAX_VALUE, false);
+ er.interval = parseIntRange(value, Integer.MIN_VALUE, Integer.MAX_VALUE, true);
+ if (er.interval < 1) {
+ Log.d(TAG, "Invalid Interval. Forcing INTERVAL to 1 from " + value);
+ er.interval = 1;
+ }
return PARSED_INTERVAL;
}
}
diff --git a/tests/src/com/android/calendarcommon/EventRecurrenceTest.java b/tests/src/com/android/calendarcommon/EventRecurrenceTest.java
index 35777eb..a058adf 100644
--- a/tests/src/com/android/calendarcommon/EventRecurrenceTest.java
+++ b/tests/src/com/android/calendarcommon/EventRecurrenceTest.java
@@ -527,6 +527,135 @@ public class EventRecurrenceTest extends TestCase {
);
}
+ // INTERVAL = 0 -> Interval = 1 bug #5676414
+ public void test20() throws Exception {
+ verifyRecurType("FREQ=YEARLY;BYMONTHDAY=18;BYMONTH=10;INTERVAL=0;",
+ /* int freq */ EventRecurrence.YEARLY,
+ /* String until */ null,
+ /* int count */ 0,
+ /* int interval */ 1,
+ /* int[] bysecond */ null,
+ /* int[] byminute */ null,
+ /* int[] byhour */ null,
+ /* int[] byday */ null,
+ /* int[] bydayNum */ null,
+ /* int[] bymonthday */ new int[]{18},
+ /* int[] byyearday */ null,
+ /* int[] byweekno */ null,
+ /* int[] bymonth */ new int[]{10},
+ /* int[] bysetpos */ null,
+ /* int wkst */ EventRecurrence.MO
+ );
+ }
+
+ // Working case: INTERVAL=1 -> Interval = 1 bug #5676414
+ public void test21() throws Exception {
+ verifyRecurType("FREQ=WEEKLY;WKST=SU;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR",
+ /* int freq */ EventRecurrence.WEEKLY,
+ /* String until */ null,
+ /* int count */ 0,
+ /* int interval */ 1,
+ /* int[] bysecond */ null,
+ /* int[] byminute */ null,
+ /* int[] byhour */ null,
+ /* int[] byday */ new int[] {
+ EventRecurrence.MO,
+ EventRecurrence.TU,
+ EventRecurrence.WE,
+ EventRecurrence.TH,
+ EventRecurrence.FR,
+ },
+ /* int[] bydayNum */ new int[]{0, 0, 0, 0, 0},
+ /* int[] bymonthday */ null,
+ /* int[] byyearday */ null,
+ /* int[] byweekno */ null,
+ /* int[] bymonth */ null,
+ /* int[] bysetpos */ null,
+ /* int wkst */ EventRecurrence.SU
+ );
+ }
+
+ // Working case: INTERVAL=2 -> Interval = 2 bug #5676414
+ public void test22() throws Exception {
+ verifyRecurType("FREQ=WEEKLY;WKST=SU;INTERVAL=2;BYDAY=MO,TU,WE,TH,FR",
+ /* int freq */ EventRecurrence.WEEKLY,
+ /* String until */ null,
+ /* int count */ 0,
+ /* int interval */ 2,
+ /* int[] bysecond */ null,
+ /* int[] byminute */ null,
+ /* int[] byhour */ null,
+ /* int[] byday */ new int[] {
+ EventRecurrence.MO,
+ EventRecurrence.TU,
+ EventRecurrence.WE,
+ EventRecurrence.TH,
+ EventRecurrence.FR,
+ },
+ /* int[] bydayNum */ new int[]{0, 0, 0, 0, 0},
+ /* int[] bymonthday */ null,
+ /* int[] byyearday */ null,
+ /* int[] byweekno */ null,
+ /* int[] bymonth */ null,
+ /* int[] bysetpos */ null,
+ /* int wkst */ EventRecurrence.SU
+ );
+ }
+
+ // COUNT < 0 -> Count = 1 bug #5676414
+ public void test23() throws Exception {
+ verifyRecurType("FREQ=WEEKLY;COUNT=-20;BYDAY=MO,TU,WE,TH,FR;",
+ /* int freq */ EventRecurrence.WEEKLY,
+ /* String until */ null,
+ /* int count */ 1,
+ /* int interval */ 0,
+ /* int[] bysecond */ null,
+ /* int[] byminute */ null,
+ /* int[] byhour */ null,
+ /* int[] byday */ new int[] {
+ EventRecurrence.MO,
+ EventRecurrence.TU,
+ EventRecurrence.WE,
+ EventRecurrence.TH,
+ EventRecurrence.FR,
+ },
+ /* int[] bydayNum */ new int[]{0, 0, 0, 0, 0},
+ /* int[] bymonthday */ null,
+ /* int[] byyearday */ null,
+ /* int[] byweekno */ null,
+ /* int[] bymonth */ null,
+ /* int[] bysetpos */ null,
+ /* int wkst */ EventRecurrence.MO
+ );
+ }
+
+ // Working case: COUNT=2 -> Count=2 bug #5676414
+ public void test24() throws Exception {
+ verifyRecurType("FREQ=WEEKLY;COUNT=2;BYDAY=MO,TU,WE,TH,FR;",
+ /* int freq */ EventRecurrence.WEEKLY,
+ /* String until */ null,
+ /* int count */ 2,
+ /* int interval */ 0,
+ /* int[] bysecond */ null,
+ /* int[] byminute */ null,
+ /* int[] byhour */ null,
+ /* int[] byday */ new int[] {
+ EventRecurrence.MO,
+ EventRecurrence.TU,
+ EventRecurrence.WE,
+ EventRecurrence.TH,
+ EventRecurrence.FR,
+ },
+ /* int[] bydayNum */ new int[]{0, 0, 0, 0, 0},
+ /* int[] bymonthday */ null,
+ /* int[] byyearday */ null,
+ /* int[] byweekno */ null,
+ /* int[] bymonth */ null,
+ /* int[] bysetpos */ null,
+ /* int wkst */ EventRecurrence.MO
+ );
+ }
+
// for your copying pleasure
public void fakeTestXX() throws Exception {
verifyRecurType("FREQ=DAILY;",