mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-02 10:34:58 +00:00
ignore invalid xml characters
This commit is contained in:
@@ -3208,7 +3208,7 @@ public class XFLConverter {
|
||||
publishSettings.writeEndElement();
|
||||
publishSettings.writeEndElement();
|
||||
} catch (XMLStreamException ex) {
|
||||
Logger.getLogger(XFLConverter.class.getName()).log(Level.SEVERE, null, ex);
|
||||
logger.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
String publishSettingsStr = publishSettings.toString();
|
||||
@@ -3653,7 +3653,7 @@ public class XFLConverter {
|
||||
result.writeEndElement();
|
||||
result.writeEndElement();
|
||||
} catch (XMLStreamException ex) {
|
||||
Logger.getLogger(XFLConverter.class.getName()).log(Level.SEVERE, null, ex);
|
||||
logger.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,12 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.xfl;
|
||||
|
||||
import com.jpexs.helpers.Helper;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.xml.namespace.NamespaceContext;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
@@ -29,6 +32,8 @@ import javax.xml.stream.XMLStreamWriter;
|
||||
*/
|
||||
public class XFLXmlWriter implements XMLStreamWriter {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(XFLXmlWriter.class.getName());
|
||||
|
||||
private String newLineCharacters = "\n"; //Helper.newLine;
|
||||
|
||||
private boolean newLine = true;
|
||||
@@ -364,6 +369,12 @@ public class XFLXmlWriter implements XMLStreamWriter {
|
||||
for (int i = 0; i < from.length; i++) {
|
||||
text = text.replace(from[i], to[i]);
|
||||
}
|
||||
|
||||
if (Helper.containsInvalidXMLCharacter(text)) {
|
||||
logger.log(Level.WARNING, "The following text contains a character which is invalid in XML: {0}", text);
|
||||
return Helper.removeInvalidXMLCharacters(text);
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
@@ -373,6 +384,11 @@ public class XFLXmlWriter implements XMLStreamWriter {
|
||||
for (int i = 0; i < from.length; i++) {
|
||||
text = text.replace(from[i], to[i]);
|
||||
}
|
||||
if (Helper.containsInvalidXMLCharacter(text)) {
|
||||
logger.log(Level.WARNING, "The following text contains a character which is invalid in XML: {0}", text);
|
||||
return Helper.removeInvalidXMLCharacters(text);
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
@@ -1117,6 +1117,17 @@ public class Helper {
|
||||
return text;
|
||||
}
|
||||
|
||||
public static boolean containsInvalidXMLCharacter(String text) {
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
char ch = text.charAt(i);
|
||||
if (!(ch > 31 || ch == 9 || ch == 10 || ch == 13)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String removeInvalidXMLCharacters(String text) {
|
||||
StringBuilder sb = new StringBuilder(text.length());
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
|
||||
Reference in New Issue
Block a user