Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Pingel2013-04-26 20:54:58 +0000
committerSteffen Pingel2013-04-26 20:54:58 +0000
commit08fac114ad5228867df38744888fd9a8e39a3d3d (patch)
treea8c498951bee739a39710264db844cae5b23cca0
parent6d34978ac097779a6b43704ff7747cfff9448b24 (diff)
downloadorg.eclipse.mylyn.tasks-08fac114ad5228867df38744888fd9a8e39a3d3d.tar.gz
org.eclipse.mylyn.tasks-08fac114ad5228867df38744888fd9a8e39a3d3d.tar.xz
org.eclipse.mylyn.tasks-08fac114ad5228867df38744888fd9a8e39a3d3d.zip
406647: [backport] task data gets corrupted when falling back to XML 1.1
Change-Id: I28a69c4aec071ae5ac72aa007285f9ca2acbedb1 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=406647
-rw-r--r--org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.mylyn.tasks.core/build.properties1
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataExternalizer.java9
-rw-r--r--org.eclipse.mylyn.tasks.tests/META-INF/MANIFEST.MF1
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataStoreTest.java74
-rw-r--r--org.eclipse.mylyn.tasks.tests/testdata/taskdata-bug406647.zipbin0 -> 2430 bytes
6 files changed, 78 insertions, 10 deletions
diff --git a/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF b/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF
index 8ec1feb95..b7c8ad6f0 100644
--- a/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF
@@ -11,7 +11,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.mylyn.commons.core;bundle-version="3.8.0",
org.eclipse.mylyn.commons.net;bundle-version="3.8.0",
org.eclipse.mylyn.commons.repositories.core;bundle-version="1.0.0",
- org.eclipse.core.runtime.compatibility.auth;resolution:=optional;x-installation:=greedy
+ org.eclipse.core.runtime.compatibility.auth;resolution:=optional;x-installation:=greedy,
+ org.apache.xerces;bundle-version="2.9.0";resolution:=optional
Export-Package: org.eclipse.mylyn.internal.provisional.tasks.core;x-internal:=true,
org.eclipse.mylyn.internal.tasks.core;x-friends:="org.eclipse.mylyn.tasks.ui,org.eclipse.mylyn.tasks.bugs",
org.eclipse.mylyn.internal.tasks.core.activity;x-friends:="org.eclipse.mylyn.tasks.ui,org.eclipse.mylyn.tasks.bugs",
diff --git a/org.eclipse.mylyn.tasks.core/build.properties b/org.eclipse.mylyn.tasks.core/build.properties
index d8c42eba4..88315cb57 100644
--- a/org.eclipse.mylyn.tasks.core/build.properties
+++ b/org.eclipse.mylyn.tasks.core/build.properties
@@ -15,3 +15,4 @@ bin.includes = META-INF/,\
src.includes = about.html,\
schema/
source.. = src/
+jars.extra.classpath = platform:/plugin/org.apache.xerces
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataExternalizer.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataExternalizer.java
index 02c1d353b..c73f1156e 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataExternalizer.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataExternalizer.java
@@ -177,7 +177,14 @@ public class TaskDataExternalizer {
}
public TaskDataState readState(InputStream in) throws IOException, SAXException {
- XMLReader parser = XMLReaderFactory.createXMLReader();
+ XMLReader parser;
+ try {
+ // use Xerces to ensure XML 1.1 is handled correctly
+ Class<?> clazz = Class.forName("org.apache.xerces.parsers.SAXParser"); //$NON-NLS-1$
+ parser = (XMLReader) clazz.newInstance();
+ } catch (Throwable e) {
+ parser = XMLReaderFactory.createXMLReader();
+ }
TaskDataStateReader handler = new TaskDataStateReader(taskRepositoryManager);
parser.setContentHandler(handler);
parser.parse(new InputSource(in));
diff --git a/org.eclipse.mylyn.tasks.tests/META-INF/MANIFEST.MF b/org.eclipse.mylyn.tasks.tests/META-INF/MANIFEST.MF
index f42fa2bf5..30baac455 100644
--- a/org.eclipse.mylyn.tasks.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.tasks.tests/META-INF/MANIFEST.MF
@@ -6,6 +6,7 @@ Bundle-Version: 3.8.4.qualifier
Bundle-Activator: org.eclipse.mylyn.tasks.tests.TasksTestsPlugin
Bundle-Vendor: Eclipse Mylyn
Require-Bundle: org.junit,
+ org.apache.xerces;bundle-version="2.9.0";resolution:=optional;x-installation:=greedy,
org.eclipse.core.expressions,
org.eclipse.core.resources,
org.eclipse.core.runtime,
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataStoreTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataStoreTest.java
index 0ad07bd3b..9c60fc9d1 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataStoreTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataStoreTest.java
@@ -16,7 +16,9 @@ import java.util.Date;
import junit.framework.TestCase;
+import org.apache.commons.lang.RandomStringUtils;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil;
import org.eclipse.mylyn.internal.tasks.core.TaskRepositoryManager;
import org.eclipse.mylyn.internal.tasks.core.data.TaskDataState;
import org.eclipse.mylyn.internal.tasks.core.data.TaskDataStore;
@@ -198,8 +200,6 @@ public class TaskDataStoreTest extends TestCase {
setupData();
data.getRoot().createAttribute("attribute").setValue("\u0000");
- File file = File.createTempFile("mylyn", null);
- file.deleteOnExit();
storage.putTaskData(file, state);
try {
@@ -213,8 +213,6 @@ public class TaskDataStoreTest extends TestCase {
setupData();
data.getRoot().createAttribute("attribute").setValue("\u0001\u001F");
- File file = File.createTempFile("mylyn", null);
- file.deleteOnExit();
storage.putTaskData(file, state);
TaskDataState state2 = storage.getTaskDataState(file);
@@ -225,8 +223,6 @@ public class TaskDataStoreTest extends TestCase {
setupData();
data.getRoot().createAttribute("attribute").setValue("\u007F\u0080");
- File file = File.createTempFile("mylyn", null);
- file.deleteOnExit();
storage.putTaskData(file, state);
TaskDataState state2 = storage.getTaskDataState(file);
@@ -237,8 +233,6 @@ public class TaskDataStoreTest extends TestCase {
setupData();
data.getRoot().createAttribute("attribute").setValue("\u0001\u001F\u007F\u0080");
- File file = File.createTempFile("mylyn", null);
- file.deleteOnExit();
storage.putTaskData(file, state);
if (System.getProperty("java.version").compareTo("1.6") < 0) {
@@ -257,4 +251,68 @@ public class TaskDataStoreTest extends TestCase {
}
}
+ public void testCorruptedData() throws Exception {
+ if (!hasXerces()) {
+ System.err.println("Skipping testCorruptedData() due to Xerces missing");
+ return;
+ }
+ state = storage.getTaskDataState(CommonTestUtil.getFile(this, "testdata/taskdata-bug406647.zip"));
+ assertFalse(state.getRepositoryData().getRoot().toString().contains("<ke"));
+ assertFalse(state.getRepositoryData().getRoot().toString().contains("<va"));
+ assertFalse(state.getRepositoryData().getRoot().toString().contains("ey>"));
+ assertFalse(state.getRepositoryData().getRoot().toString().contains("al>"));
+ }
+
+ private boolean hasXerces() {
+ try {
+ Class.forName("org.apache.xerces.parsers.SAXParser");
+ return true;
+ } catch (ClassNotFoundException e) {
+ return false;
+ }
+ }
+
+ public void testRandomDataXml_1_0() throws Exception {
+ randomData(32, Integer.MAX_VALUE);
+ }
+
+ public void testRandomDataXml_1_1() throws Exception {
+ if (!hasXerces()) {
+ System.err.println("Skipping testRandomDataXml_1_1 due to Xerces missing");
+ return;
+ }
+ randomData(0, Integer.MAX_VALUE);
+ }
+
+ private void randomData(int start, int end) throws Exception {
+ setupData();
+
+ for (int i = 0; i < 1000; i++) {
+ TaskAttribute attribute = data.getRoot().createAttribute("testId");
+ attribute.getMetaData().setLabel(generateString(start, end));
+ attribute.putOption(generateString(start, end), generateString(start, end));
+ attribute.putOption(generateString(start, end), generateString(start, end));
+ attribute.addValue(generateString(start, end));
+ attribute.addValue(generateString(start, end));
+ if (start == 0) {
+ // ensure that XML is read as version 1.1
+ attribute.addValue(generateString(start, end) + "\u0001");
+ }
+ }
+
+ String expectedValue = data.getRoot().toString();
+ storage.putTaskData(file, state);
+
+ state = storage.getTaskDataState(file);
+ String actualValue = state.getRepositoryData().getRoot().toString();
+ assertEquals(expectedValue, actualValue);
+ }
+
+ /**
+ * Returns a random string that doesn't contain "key" or "val".
+ */
+ private String generateString(int start, int end) {
+ return RandomStringUtils.random(1000, start, end, true, true);
+ }
+
}
diff --git a/org.eclipse.mylyn.tasks.tests/testdata/taskdata-bug406647.zip b/org.eclipse.mylyn.tasks.tests/testdata/taskdata-bug406647.zip
new file mode 100644
index 000000000..c4ddcb851
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/testdata/taskdata-bug406647.zip
Binary files differ

Back to the top