Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,9 @@ public void flush() throws IOException {
// --- utility methods

protected void writeAttributeValue(String value, Writer out) throws IOException {
if (value == null) {
return;
}
// .[apostrophe and <, & escaped],
final char quot = attributeUseApostrophe ? '\'' : '"';
final String quotEntity = attributeUseApostrophe ? "&apos;" : "&quot;";
Expand Down Expand Up @@ -908,6 +911,9 @@ protected void writeAttributeValue(String value, Writer out) throws IOException
}

protected void writeElementContent(String text, Writer out) throws IOException {
if (text == null) {
return;
}
// escape '<', '&', ']]>', <32 if necessary
int pos = 0;
for (int i = 0; i < text.length(); i++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.codehaus.plexus.util.xml.pull;

import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.Arrays;
Expand Down Expand Up @@ -55,4 +56,19 @@ private String expectedOutput() {
out.append("</root>");
return out.toString();
}

/**
* Tests MJAVADOC-793.
*/
@Test
public void testWriteNullValues() throws IOException {
// should be no-ops
new MXSerializer().writeElementContent(null, null);
new MXSerializer().writeAttributeValue(null, null);
final StringWriter stringWriter = new StringWriter();
new MXSerializer().writeElementContent(null, stringWriter);
assertEquals("", stringWriter.toString());
new MXSerializer().writeAttributeValue(null, stringWriter);
assertEquals("", stringWriter.toString());
}
}