diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/UnparsedIQ.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/UnparsedIQ.java
index e363d2e303..8cd2146f80 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/packet/UnparsedIQ.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/UnparsedIQ.java
@@ -16,6 +16,8 @@
*/
package org.jivesoftware.smack.packet;
+import org.jivesoftware.smack.util.StringUtils;
+
/**
* An IQ stanzas that could not be parsed because no provider was found.
*/
@@ -34,7 +36,12 @@ public CharSequence getContent() {
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
- xml.escape(content);
+ if (StringUtils.isEmpty(content)) {
+ xml.setEmptyElement();
+ } else {
+ xml.rightAngleBracket();
+ xml.escape(content);
+ }
return xml;
}
}
diff --git a/smack-core/src/test/java/org/jivesoftware/smack/packet/IqTest.java b/smack-core/src/test/java/org/jivesoftware/smack/packet/IqTest.java
index 041c669814..2101daca41 100644
--- a/smack-core/src/test/java/org/jivesoftware/smack/packet/IqTest.java
+++ b/smack-core/src/test/java/org/jivesoftware/smack/packet/IqTest.java
@@ -58,4 +58,19 @@ public void testIqWithXmlns(SmackTestUtil.XmlPullParserKind parserKind) throws E
IQ iq = PacketParserUtils.parseIQ(parser);
assertXmlSimilar(iqXml, iq.toXML());
}
+
+ @ParameterizedTest
+ @EnumSource(SmackTestUtil.XmlPullParserKind.class)
+ public void testUnparsedIq(SmackTestUtil.XmlPullParserKind parserKind) throws Exception {
+ final String iqXml = "" +
+ "" +
+ "";
+ final String expected = ""
+ + "<query xmlns='jabber:iq:version'/>"
+ + "";
+
+ XmlPullParser parser = SmackTestUtil.getParserFor(iqXml, "iq", parserKind);
+ IQ iq = PacketParserUtils.parseIQ(parser);
+ assertXmlSimilar(expected, iq.toXML());
+ }
}