From 4fea0427b74435bae83ad13a97c7e49e10de2b87 Mon Sep 17 00:00:00 2001 From: Robin Shen Date: Fri, 16 Dec 2022 16:07:00 +0800 Subject: [PATCH] Fix issue #1038 - Upgrade failure (7.6.0 -> 7.7.0 or 7.8.8) --- .../server/migration/VersionedXmlDoc.java | 22 +++++++++++-------- .../java/io/onedev/server/product/Test.java | 8 +++++-- 2 files changed, 19 insertions(+), 11 deletions(-) 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, "