Skip to content

The Unified and Autonomous Development Platform

Fix issue #1038 - Upgrade failure (7.6.0 -> 7.7.0 or 7.8.8)

Robin Shen4fea0427b744
diff --git a/server-core/src/main/java/io/onedev/server/migration/VersionedXmlDoc.java b/server-core/src/main/java/io/onedev/server/migration/VersionedXmlDoc.java
index d9ef0a1c5d..464613845e 100644
--- a/server-core/src/main/java/io/onedev/server/migration/VersionedXmlDoc.java
+++ b/server-core/src/main/java/io/onedev/server/migration/VersionedXmlDoc.java
@@ -15,6 +15,8 @@ import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import javax.annotation.Nullable;
@@ -57,11 +59,13 @@ public final class VersionedXmlDoc implements Document, Externalizable {
private static final long serialVersionUID = 1L;
+ private static final Pattern SPECIAL_CHARACTERS = Pattern.compile("&#\\d+;");
+
private transient String xml;
private transient Document wrapped;
-
- public VersionedXmlDoc() {
+
+ public VersionedXmlDoc() {
wrapped = DocumentHelper.createDocument();
}
@@ -401,14 +405,14 @@ public final class VersionedXmlDoc implements Document, Externalizable {
public static VersionedXmlDoc fromXML(String xml) {
try {
- // May contain some invalid characters, parse with 1.1
+ // remove special characters
+ Matcher matcher = SPECIAL_CHARACTERS.matcher(xml);
+ StringBuffer buffer = new StringBuffer();
+ while (matcher.find())
+ matcher.appendReplacement(buffer, "");
+ matcher.appendTail(buffer);
- // This is added originally due to issue #177, but writing XML with 1.0 and
- // reading with 1.1 resulting the issue #1038. Now input "" in an issue comment
- // and it seems that the sequence is escaped as "" in the backup, and
- // restore can run successfully without any issues. So just revert back
- // xml = StringUtils.replace(xml, "<?xml version=\"1.0\"", "<?xml version=\"1.1\"");
- return new VersionedXmlDoc(new SAXReader().read(new StringReader(xml)));
+ return new VersionedXmlDoc(new SAXReader().read(new StringReader(buffer.toString())));
} catch (Exception e) {
throw ExceptionUtils.unchecked(e);
}
diff --git a/server-product/src/test/java/io/onedev/server/product/Test.java b/server-product/src/test/java/io/onedev/server/product/Test.java
index e29e84b6bf..32378448da 100644
--- a/server-product/src/test/java/io/onedev/server/product/Test.java
+++ b/server-product/src/test/java/io/onedev/server/product/Test.java
@@ -1,9 +1,13 @@
package io.onedev.server.product;
+import java.io.IOException;
+
+import org.dom4j.DocumentException;
+
public class Test {
@org.junit.Test
- public void test() {
+ public void test() throws IOException, DocumentException {
}
-
+
}
\ No newline at end of file