Skip to content

Commit

Permalink
Fix #467
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jul 8, 2021
1 parent ede336c commit bf8d525
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 50 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Project: jackson-dataformat-xml
(reported by Fabian M)
#465: ArrayIndexOutOfBoundsException in UTF8Reader (ossfuzz)
(reported by Fabian M)
#467: Ignore contents of elements annotated with xsi:nil="true" (when
xsi:nil handling enabled)
#468: Add `FromXmlParser.Feature.PROCESS_XSI_NIL` to allow disabling
processing of `xsi:nil` attributes on reading
#474: Empty String ("") parsed as 0 for int even if
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,19 +419,13 @@ private final int _next() throws XMLStreamException
++_nextAttributeIndex;
// fall through
case XML_START_ELEMENT: // attributes to return?

// 06-Sep-2019, tatu: `xsi:nil` to induce "real" null value?
if (_xsiNilFound) {
_xsiNilFound = false;
switch (_skipUntilTag()) {
case XMLStreamConstants.END_ELEMENT:
return _handleEndElement();
case XMLStreamConstants.END_DOCUMENT:
throw new IllegalStateException("Unexpected end-of-input after null token");
default:
}
throw new IllegalStateException(
"Unexpected START_ELEMENT after null token (inside element with 'xsi:nil' attribute)");
// 08-Jul-2021, tatu: as per [dataformat-xml#467] just skip anything
// element might have, no need to ensure it was empty
_xmlReader.skipElement();
return _handleEndElement();
}
if (_nextAttributeIndex < _attributeCount) {
//System.out.println(" XmlTokenStream._next(): Got attr(s)!");
Expand Down Expand Up @@ -564,23 +558,6 @@ private final String _collectUntilTag() throws XMLStreamException
}
}

// Called to simply skip tokens until start/end tag, or end-of-document found
private final int _skipUntilTag() throws XMLStreamException
{
while (_xmlReader.hasNext()) {
int type;
switch (type = _xmlReader.next()) {
case XMLStreamConstants.START_ELEMENT:
case XMLStreamConstants.END_ELEMENT:
case XMLStreamConstants.END_DOCUMENT:
return type;
default:
// any other type (proc instr, comment etc) is just ignored
}
}
throw new IllegalStateException("Expected to find a tag, instead reached end of input");
}

// Called to skip tokens until start/end tag (or end-of-document) found, but
// also collecting cdata until then, if any found, for possible "mixed content"
// to report
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ public void testRootPojoAsNonNull() throws Exception
assertNotNull(bean);
}

// [dataformat-xml#467]: Ok to have contents within "xsi:nil" element
public void testXsiNilWithNonEmptyElement() throws Exception
{
JsonNode node = MAPPER.readTree(
"<e>"
+"<h "+XSI_NS_DECL+" xsi:nil='true'><child>stuff</child></h>"
+"</e>"
);
assertNotNull(node);
assertEquals(a2q("{'h':null}"), node.toString());
}

// [dataformat-xml#468]: Allow disabling xsi:nil special handling
public void testDisableXsiNilLeafProcessing() throws Exception
{
Expand Down

This file was deleted.

0 comments on commit bf8d525

Please sign in to comment.