Skip to content

Commit 0b3cd5c

Browse files
Fix after review
1 parent 23329e7 commit 0b3cd5c

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

src/main/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriter.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
import java.util.regex.Pattern;
2525

2626
/**
27-
* Implementation of XMLWriter which emits nicely formatted documents.
28-
*
27+
* <p>Implementation of XMLWriter which emits nicely formatted documents.</p>
2928
*
29+
* <p>C0 controls chars are omitted from output</p>
3030
*/
3131
public class PrettyPrintXMLWriter implements XMLWriter {
3232
/** Line separator ("\n" on UNIX) */
@@ -226,9 +226,9 @@ private static String escapeXml(String text) {
226226

227227
private static final Pattern crlf = Pattern.compile(crlf_str);
228228

229-
private static final Pattern lowers = Pattern.compile("([\000-\037])");
229+
private static final Pattern lowers = Pattern.compile("([\\x00-\\x1F])");
230230

231-
private static final Pattern lowersText = Pattern.compile("([\000-\010\013-\014\016-\037])");
231+
private static final Pattern illegalC0Characters = Pattern.compile("([\\x00-\\x08\\x0B-\\x0C\\x0E-\\x1F])");
232232

233233
private static String escapeXmlAttribute(String text) {
234234
text = escapeXmlText(text);
@@ -252,12 +252,12 @@ private static String escapeXmlAttribute(String text) {
252252
private static String escapeXmlText(String text) {
253253
text = escapeXml(text);
254254

255-
Matcher m = lowersText.matcher(text);
255+
Matcher matcher = illegalC0Characters.matcher(text);
256256
StringBuffer b = new StringBuffer();
257-
while (m.find()) {
258-
m = m.appendReplacement(b, "");
257+
while (matcher.find()) {
258+
matcher = matcher.appendReplacement(b, "");
259259
}
260-
m.appendTail(b);
260+
matcher.appendTail(b);
261261

262262
return b.toString();
263263
}

src/main/java/org/codehaus/plexus/util/xml/pull/MXSerializer.java

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* <li>PROPERTY_SERIALIZER_INDENTATION
2525
* <li>PROPERTY_SERIALIZER_LINE_SEPARATOR
2626
* </ul>
27+
* <p>C0 controls chars are omitted from output</p>
2728
*/
2829
public class MXSerializer implements XmlSerializer {
2930
protected static final String XML_URI = "http://www.w3.org/XML/1998/namespace";

src/test/java/org/codehaus/plexus/util/xml/pull/MXSerializerTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ private String expectedOutput() {
4747
out.append("<?xml version=\"1.0\" standalone=\"yes\"?>");
4848
out.append("<root>");
4949
out.append("<char>BACKSPACE: </char>");
50-
out.append("<char>CHARACTER TABULATION: \t");
51-
out.append("</char><char>LINE FEED (LF): \n");
52-
out.append("</char><char>LINE TABULATION: </char>");
53-
out.append("<char>CARRIAGE RETURN (CR): \r");
54-
out.append("</char><char>SHIFT IN: </char>");
50+
out.append("<char>CHARACTER TABULATION: \t</char>");
51+
out.append("<char>LINE FEED (LF): \n</char>");
52+
out.append("<char>LINE TABULATION: </char>");
53+
out.append("<char>CARRIAGE RETURN (CR): \r</char>");
54+
out.append("<char>SHIFT IN: </char>");
5555
out.append("</root>");
5656
return out.toString();
5757
}

0 commit comments

Comments
 (0)