From 29bcb69e55fdd44848dc532d37f842504f4215aa Mon Sep 17 00:00:00 2001 From: Baron Roberts Date: Sat, 23 Mar 2024 15:09:33 -0700 Subject: [PATCH] Use "unicode-" rather than "ctrl-" for invalid XML characters. --- CHANGELOG.md | 3 ++- src/main/java/org/cthing/xmlwriter/XmlWriter.java | 4 ++-- src/test/java/org/cthing/xmlwriter/XmlWriterTest.java | 8 ++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3291f93..7143467 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +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 in hexidecimal (e.g. `ctrl-0xFFFE`) 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 - 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 1073e11..6a433c9 100755 --- a/src/main/java/org/cthing/xmlwriter/XmlWriter.java +++ b/src/main/java/org/cthing/xmlwriter/XmlWriter.java @@ -2657,7 +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 ctrl-0xN} where {@code N} + * numeric character reference. Invalid XML control characters are written as {code unicode-0xN} where {@code N} * is the hexidecimal value of the invalid character. * * @param c Character to write @@ -2681,7 +2681,7 @@ void writeEscaped(final int c) throws SAXException { writeRaw(Integer.toHexString(c).toUpperCase()); writeRaw(';'); } else { - writeRaw("ctrl-0x"); + 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 1082a6f..e2ac10f 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©ctrl-0x1Actrl-0xFFFE😃\t\n"; + final String testStringOut = "<Hello &<>\" World©unicode-0x1Aunicode-0xFFFE😃\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, "ctrl-0x0"), - arguments(0x1F, "ctrl-0x1F"), - arguments(0xFFFF, "ctrl-0xFFFF"), + arguments(0x0, "unicode-0x0"), + arguments(0x1F, "unicode-0x1F"), + arguments(0xFFFF, "unicode-0xFFFF"), arguments(0x7F, ""), arguments(0xD7FF, "퟿"), arguments(0xE000, ""),