GeezerVison is showing github.com — Fix for MJAVADOC-793 · codehaus-plexus/plexus-xml@b2263d5
File tree
Expand file treeCollapse file tree
Open diff view settings
main/java/org/codehaus/plexus/util/xml/pull test/java/org/codehaus/plexus/util/xml/pull
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/main/java/org/codehaus/plexus/util/xml/pull/MXSerializer.java +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -854,6 +854,9 @@ public void flush() throws IOException { |
854 | 854 | // --- utility methods |
855 | 855 |
|
856 | 856 | protected void writeAttributeValue(String value, Writer out) throws IOException { |
| 857 | + if (value == null) { |
| 858 | + return; |
| 859 | + } |
857 | 860 | // .[apostrophe and <, & escaped], |
858 | 861 | final char quot = attributeUseApostrophe ? '\'' : '"'; |
859 | 862 | final String quotEntity = attributeUseApostrophe ? "'" : """; |
@@ -908,6 +911,9 @@ protected void writeAttributeValue(String value, Writer out) throws IOException |
908 | 911 | } |
909 | 912 |
|
910 | 913 | protected void writeElementContent(String text, Writer out) throws IOException { |
| 914 | + if (text == null) { |
| 915 | + return; |
| 916 | + } |
911 | 917 | // escape '<', '&', ']]>', <32 if necessary |
912 | 918 | int pos = 0; |
913 | 919 | for (int i = 0; i < text.length(); i++) { |
|
Collapse file
Copy file name to clipboardExpand all lines: src/test/java/org/codehaus/plexus/util/xml/pull/MXSerializerTest.java +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | package org.codehaus.plexus.util.xml.pull; |
2 | 2 |
|
| 3 | +import java.io.IOException; |
3 | 4 | import java.io.StringReader; |
4 | 5 | import java.io.StringWriter; |
5 | 6 | import java.util.Arrays; |
@@ -55,4 +56,19 @@ private String expectedOutput() { |
55 | 56 | out.append("</root>"); |
56 | 57 | return out.toString(); |
57 | 58 | } |
| 59 | + |
| 60 | + /** |
| 61 | + * Tests MJAVADOC-793. |
| 62 | + */ |
| 63 | + @Test |
| 64 | + public void testMJAVADOC793() throws IOException { |
| 65 | + // should be no-ops |
| 66 | + new MXSerializer().writeElementContent(null, null); |
| 67 | + new MXSerializer().writeAttributeValue(null, null); |
| 68 | + final StringWriter stringWriter = new StringWriter(); |
| 69 | + new MXSerializer().writeElementContent(null, stringWriter); |
| 70 | + assertEquals("", stringWriter.toString()); |
| 71 | + new MXSerializer().writeAttributeValue(null, stringWriter); |
| 72 | + assertEquals("", stringWriter.toString()); |
| 73 | + } |
58 | 74 | } |