Sanity check for weird repeat values

pull/14/head
Sam Bosley 12 years ago
parent 0d4c6555b8
commit 35acb15c91

@ -170,12 +170,15 @@ public class AstridNewSyncMigrator {
String recurrence = instance.getValue(Task.RECURRENCE);
if (!TextUtils.isEmpty(recurrence)) {
String fromCompletion = ";FROM=COMPLETION";
boolean repeatAfterCompletion = instance.getFlag(Task.FLAGS, Task.FLAG_REPEAT_AFTER_COMPLETION);
instance.setFlag(Task.FLAGS, Task.FLAG_REPEAT_AFTER_COMPLETION, false);
recurrence = recurrence.replaceAll("BYDAY=;", "");
if (repeatAfterCompletion)
recurrence = recurrence + ";FROM=COMPLETION";
if (fromCompletion.equals(recurrence))
recurrence = "";
else if (repeatAfterCompletion)
recurrence = recurrence + fromCompletion;
instance.setValue(Task.RECURRENCE, recurrence);
}
}

@ -4,6 +4,7 @@ import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
@ -110,6 +111,7 @@ public class ChangesHappened<TYPE extends RemoteModel, OE extends OutstandingEnt
JSONArray array = new JSONArray();
AtomicInteger uploadCounter = new AtomicInteger();
PropertyToJSONVisitor visitor = new PropertyToJSONVisitor();
AtomicReference<Object> valueRef = new AtomicReference<Object>();
for (OE change : changes) {
try {
String localColumn = change.getValue(OutstandingEntry.COLUMN_STRING_PROPERTY);
@ -150,9 +152,12 @@ public class ChangesHappened<TYPE extends RemoteModel, OE extends OutstandingEnt
throw new RuntimeException("No server column found for local column " + localColumn + " in table " + table);
Object value = localProperty.accept(visitor, change);
if (!validateValue(localProperty, value))
valueRef.set(value);
if (!validateValue(localProperty, valueRef))
return null;
value = valueRef.get();
if (value == null)
changeJson.put("value", JSONObject.NULL);
else {
@ -218,10 +223,13 @@ public class ChangesHappened<TYPE extends RemoteModel, OE extends OutstandingEnt
// Return false if value is detected to be something that would definitely cause a server error
// (e.g. empty task title, etc.)
private boolean validateValue(Property<?> property, Object value) {
private boolean validateValue(Property<?> property, AtomicReference<Object> valueRef) {
if (Task.TITLE.equals(property)) {
if (!(value instanceof String) || TextUtils.isEmpty((String) value))
if (!(valueRef.get() instanceof String) || TextUtils.isEmpty((String) valueRef.get()))
return false;
} else if (Task.RECURRENCE.equals(property)) {
if (";FROM=COMPLETION".equals(valueRef.get()))
valueRef.set("");
}
return true;
}

Loading…
Cancel
Save