Disabled XML escaping when reencoding to ensure invalid chars cause an error

This commit is contained in:
Vhati 2017-12-30 03:52:28 -05:00
parent 70f49e7e98
commit 91be0845e5
3 changed files with 16 additions and 1 deletions

View file

@ -19,6 +19,7 @@
"Made the comments in boilerplace mod metadata optional", "Made the comments in boilerplace mod metadata optional",
"Fixed omitted Validate warnings for PNG files", "Fixed omitted Validate warnings for PNG files",
"Added Validate warnings about FTL 1.6.1+ for TTF, MP3, and PNG files", "Added Validate warnings about FTL 1.6.1+ for TTF, MP3, and PNG files",
"Disabled XML escaping when reencoding to ensure invalid chars cause an error",
"Changed logging framework to SLF4J/Logback", "Changed logging framework to SLF4J/Logback",
"Changed command line parser to picocli" "Changed command line parser to picocli"
] ]

View file

@ -4,6 +4,7 @@ Changelog
- Edited a comment in boilerplate mod metadata to include AE ships - Edited a comment in boilerplate mod metadata to include AE ships
- Made the comments in boilerplace mod metadata optional - Made the comments in boilerplace mod metadata optional
- Fixed omitted Validate warnings for PNG files - Fixed omitted Validate warnings for PNG files
- Disabled XML escaping when reencoding to ensure invalid chars cause an error
- Added Validate warnings about FTL 1.6.1+ for TTF, MP3, and PNG files - Added Validate warnings about FTL 1.6.1+ for TTF, MP3, and PNG files
- Changed logging framework to SLF4J/Logback - Changed logging framework to SLF4J/Logback
- Changed command line parser to picocli - Changed command line parser to picocli

View file

@ -9,6 +9,7 @@ import org.jdom2.Content;
import org.jdom2.Document; import org.jdom2.Document;
import org.jdom2.Element; import org.jdom2.Element;
import org.jdom2.Namespace; import org.jdom2.Namespace;
import org.jdom2.output.EscapeStrategy;
import org.jdom2.output.Format; import org.jdom2.output.Format;
import org.jdom2.output.LineSeparator; import org.jdom2.output.LineSeparator;
import org.jdom2.output.XMLOutputter; import org.jdom2.output.XMLOutputter;
@ -153,6 +154,9 @@ public class SloppyXMLOutputProcessor extends AbstractXMLOutputProcessor {
* is encoding bytes to match. If encoding is null, the default * is encoding bytes to match. If encoding is null, the default
* is "UTF-8". * is "UTF-8".
* *
* There will be no XML character entity escaping, which would have allowed
* otherwise unmappable characters to print without errors.
*
* LineEndings will be CR-LF. Except for comments!? * LineEndings will be CR-LF. Except for comments!?
*/ */
public static void sloppyPrint( Document doc, Writer writer, String encoding ) throws IOException { public static void sloppyPrint( Document doc, Writer writer, String encoding ) throws IOException {
@ -163,7 +167,16 @@ public class SloppyXMLOutputProcessor extends AbstractXMLOutputProcessor {
format.setIndent( "\t" ); format.setIndent( "\t" );
format.setLineSeparator( LineSeparator.CRNL ); format.setLineSeparator( LineSeparator.CRNL );
if ( encoding != null ) format.setEncoding( encoding ); if ( encoding != null ) {
format.setEncoding( encoding );
}
format.setEscapeStrategy(new EscapeStrategy() {
@Override
public boolean shouldEscape( char ch ) {
return false;
}
});
XMLOutputter outputter = new XMLOutputter( format, new SloppyXMLOutputProcessor() ); XMLOutputter outputter = new XMLOutputter( format, new SloppyXMLOutputProcessor() );
outputter.output( doc, writer ); outputter.output( doc, writer );