Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow nulls for write elements in MXSerializer #29

Merged
merged 1 commit into from
May 21, 2024
Merged
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
@@ -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;";
@@ -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++) {
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;
@@ -55,4 +56,19 @@ private String expectedOutput() {
out.append("</root>");
return out.toString();
}

/**
* Tests MJAVADOC-793.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that comment is wrong here as well.

*/
@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());
}
}