diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index c019d3103..94ff8213d 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -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 diff --git a/src/main/java/com/fasterxml/jackson/dataformat/xml/deser/XmlTokenStream.java b/src/main/java/com/fasterxml/jackson/dataformat/xml/deser/XmlTokenStream.java index a2bfd4a2b..8cee6ae7f 100644 --- a/src/main/java/com/fasterxml/jackson/dataformat/xml/deser/XmlTokenStream.java +++ b/src/main/java/com/fasterxml/jackson/dataformat/xml/deser/XmlTokenStream.java @@ -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)!"); @@ -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 diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XsiNilBasicTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XsiNilBasicTest.java index ceeb0c0cf..c6ea26b3a 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XsiNilBasicTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XsiNilBasicTest.java @@ -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( +"" ++"stuff" ++"" + ); + assertNotNull(node); + assertEquals(a2q("{'h':null}"), node.toString()); + } + // [dataformat-xml#468]: Allow disabling xsi:nil special handling public void testDisableXsiNilLeafProcessing() throws Exception { diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/XsiNilEnableDisable467Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/XsiNilEnableDisable467Test.java deleted file mode 100644 index e3cc1a807..000000000 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/XsiNilEnableDisable467Test.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.fasterxml.jackson.dataformat.xml.failing; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; - -public class XsiNilEnableDisable467Test extends XmlTestBase -{ - private final static String XSI_NS_DECL = "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"; - - private final XmlMapper MAPPER = newMapper(); - - // [databind#467] / [databind#467]: xsi:nil handling of nested elements etc - public void testNilAsNodeLeaf() throws Exception - { - JsonNode node = MAPPER.readTree( -"" -+"" -+"" - ); - assertNotNull(node); - } -}