From 1e48ed448e02b642541f2b1960c27330471e8850 Mon Sep 17 00:00:00 2001 From: Baron Roberts Date: Thu, 28 Mar 2024 17:18:33 -0700 Subject: [PATCH] No longer escape and write characters considered to be invalid according to the XML 1.0 spec. --- CHANGELOG.md | 4 ++-- src/main/java/org/cthing/xmlwriter/XmlWriter.java | 6 +----- src/test/java/org/cthing/xmlwriter/XmlWriterTest.java | 8 ++++---- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7143467..bf57452 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,8 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Numeric character entities are now written in hexidecimal (e.g. `©`) rather than decimal -- Invalid XML characters are now written using the prefix `unicode-` (e.g. `unicode-0xFFFE`) rather - than `ctrl-` and using hexidecimal (e.g. `unicode-0xFFFE`) rather than decimal for the character code +- Invalid XML characters are no longer written. In previous versions, they were written in decimal with the prefix + "ctrl-". - Changed JSR-305 dependency from `implementation` to `api` ## [2.0.1] - 2023-12-23 diff --git a/src/main/java/org/cthing/xmlwriter/XmlWriter.java b/src/main/java/org/cthing/xmlwriter/XmlWriter.java index 6a433c9..a09a40d 100755 --- a/src/main/java/org/cthing/xmlwriter/XmlWriter.java +++ b/src/main/java/org/cthing/xmlwriter/XmlWriter.java @@ -2657,8 +2657,7 @@ void writeEscaped(final char[] carr, final int start, final int length) throws S /** * Writes the specified character to the output escaping the '&', '<', and '>' characters using the * standard XML escape sequences. Control characters and characters outside the ASCII range are escaped using a - * numeric character reference. Invalid XML control characters are written as {code unicode-0xN} where {@code N} - * is the hexidecimal value of the invalid character. + * numeric character reference. Invalid XML characters are not written. * * @param c Character to write * @throws SAXException If there is an error writing the character. The SAXException wraps an IOException. @@ -2680,9 +2679,6 @@ void writeEscaped(final int c) throws SAXException { writeRaw("&#x"); writeRaw(Integer.toHexString(c).toUpperCase()); writeRaw(';'); - } else { - writeRaw("unicode-0x"); - writeRaw(Integer.toHexString(c).toUpperCase()); } } } diff --git a/src/test/java/org/cthing/xmlwriter/XmlWriterTest.java b/src/test/java/org/cthing/xmlwriter/XmlWriterTest.java index e2ac10f..b958c8b 100755 --- a/src/test/java/org/cthing/xmlwriter/XmlWriterTest.java +++ b/src/test/java/org/cthing/xmlwriter/XmlWriterTest.java @@ -114,7 +114,7 @@ void testNeedsEscaping(final String str, final boolean needsEscaping) { @DisplayName("Write an array with escaping") void testWriteEscapedArray() throws Exception { final String testStringIn = "\" World\u00A9\u001A\uFFFE\uD83D\uDE03\t\n"; - final String testStringOut = "<Hello &<>\" World©unicode-0x1Aunicode-0xFFFE😃\t\n"; + final String testStringOut = "<Hello &<>\" World©😃\t\n"; this.xmlWriter.writeEscaped(testStringIn.toCharArray(), 0, testStringIn.length()); @@ -133,9 +133,9 @@ public static Stream writeEscapedProvider() { arguments('\n', "\n"), arguments('\t', "\t"), arguments('\r', "\r"), - arguments(0x0, "unicode-0x0"), - arguments(0x1F, "unicode-0x1F"), - arguments(0xFFFF, "unicode-0xFFFF"), + arguments(0x0, ""), + arguments(0x1F, ""), + arguments(0xFFFF, ""), arguments(0x7F, ""), arguments(0xD7FF, "퟿"), arguments(0xE000, ""),