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

Conversation

garydgregory
Copy link
Contributor

@garydgregory garydgregory commented May 20, 2024

https://issues.apache.org/jira/browse/MJAVADOC-793

Allow nulls for write elements in MXSerializer.

@slawekjaranowski
Copy link
Member

@garydgregory thanks ... I afraid thet we will have a conflict with my PR #28

If you let me I first merge my PR and that you can rebase your

@garydgregory garydgregory force-pushed the MJAVADOC-793 branch 2 times, most recently from 8a472f5 to e03c11f Compare May 20, 2024 14:34
@garydgregory
Copy link
Contributor Author

@slawekjaranowski
OK, done.

@slawekjaranowski
Copy link
Member

@michael-o @elharo can you also look at it 😄

@michael-o
Copy link
Member

I'd like to see this rebased first...

@michael-o
Copy link
Member

After the rebase is done let's try MJAVADOC again with a snapshot of Plexus XML and see what happens.

@garydgregory
Copy link
Contributor Author

I rebased on master again.

Comment on lines 69 to 71
new MXSerializer().writeElementContent(null, stringWriter);
new MXSerializer().writeAttributeValue(null, stringWriter);
Copy link
Member

Choose a reason for hiding this comment

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

should support ?

new MXSerializer().writeElementContent("value", null);
new MXSerializer().writeAttributeValue("value", null);

Copy link
Member

Choose a reason for hiding this comment

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

Also add some of assertions for what content of stringWriter should be.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@slawekjaranowski
Copy link
Member

Please also change of PR / commit message to show what really is changed, what is root cause eg

Allow nulls for write elements in MXSerializer

@michael-o
Copy link
Member

Test:

	 public static void main(String[] args) throws ParserConfigurationException, TransformerException {
			Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
			Element root = doc.createElement("root");
			root.setTextContent(null);
			root.setAttribute("foo", null);
			doc.appendChild(root);

			DOMSource domSource = new DOMSource(doc);
			StreamResult result = new StreamResult(System.out);
	        TransformerFactory tf = TransformerFactory.newInstance();
	        Transformer transformer = tf.newTransformer();
	        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
	        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
	        transformer.transform(domSource, result);
		}

output:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<root foo=""/>

@michael-o
Copy link
Member

What about the pretty printer?

Copy link

@elharo elharo left a comment

Choose a reason for hiding this comment

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

some suggestion. I don't see anything actually incorrect here.

} else {
if (value != null) {
// .[apostrophe and <, & escaped],
final char quot = attributeUseApostrophe ? '\'' : '"';
Copy link

Choose a reason for hiding this comment

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

Not sure why we even make a choice here. Would be simpler to pick one and stick with it.

out.write("&gt;");
} else if (ch == quot) {
if (i > pos) out.write(value.substring(pos, i));
out.write(quotEntity);
pos = i + 1;
} else if (ch < 32) {
// in XML 1.0 only legal character are #x9 | #xA | #xD
Copy link

Choose a reason for hiding this comment

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

legal C0 characters

// pass through

// } else if(ch == 13) { //escape
// and they must be escaped otherwise in attribute value they are normalized to spaces
Copy link

Choose a reason for hiding this comment

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

escaped;

pos = i + 1;
} else {
throw new IllegalStateException(
"character " + Integer.toString(ch) + " is not allowed in output" + getLocation());
Copy link

Choose a reason for hiding this comment

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

IllegalArgumentException

} else {
throw new IllegalStateException(
"character " + Integer.toString(ch) + " is not allowed in output" + getLocation());
// in XML 1.1 legal are [#x1-#xD7FF]
Copy link

Choose a reason for hiding this comment

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

I'd delete all this commented code

if (ch == 9 || ch == 10 || ch == 13) {
// pass through

// } else if(ch == 13) { //escape
Copy link

Choose a reason for hiding this comment

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

delete commented code

@garydgregory
Copy link
Contributor Author

@elharo Thank you for your comments. I'll let the Maven team address those since I feel they are out of scope for this PR.

* Tests MJAVADOC-793.
*/
@Test
public void testMJAVADOC793() throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

This should be renamed. This is not related to the Javadoc plugin. IT simply does not allow null values. testNullValues()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done: testWriteNullValues().

@slawekjaranowski
Copy link
Member

@elharo Thank you for your comments. I'll let the Maven team address those since I feel they are out of scope for this PR.

you right if needed should be fixed in separate PR

Copy link
Member

@slawekjaranowski slawekjaranowski left a comment

Choose a reason for hiding this comment

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

looks OK please chenge test name and commit PR title

@garydgregory garydgregory changed the title Fix for MJAVADOC-793 Allow nulls for write elements in MXSerializer May 21, 2024
@garydgregory garydgregory requested a review from michael-o May 21, 2024 20:02
@slawekjaranowski
Copy link
Member

@michael-o I hope your doubts was resolved, so I will merge and process forward

@slawekjaranowski slawekjaranowski added the bug Something isn't working label May 21, 2024
@slawekjaranowski slawekjaranowski merged commit 43dbdca into codehaus-plexus:master May 21, 2024
11 checks passed
@garydgregory garydgregory deleted the MJAVADOC-793 branch May 21, 2024 21:49
@garydgregory
Copy link
Contributor Author

TY @slawekjaranowski

@@ -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.

@michael-o
Copy link
Member

@michael-o I hope your doubts was resolved, so I will merge and process forward

Yes, but my question about the PrettyPrinter remains open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants