Skip to content

Commit

Permalink
[core] fix toXml for UnparsedIQ
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-sb committed Sep 5, 2024
1 parent 38c6dd2 commit 609781b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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;
}
}
15 changes: 15 additions & 0 deletions smack-core/src/test/java/org/jivesoftware/smack/packet/IqTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<iq xmlns='jabber:client' type='get' id='test-1'>" +
"<query xmlns='jabber:iq:version'/>" +
"</iq>";
final String expected = "<iq xmlns='jabber:client' id='test-1' type='get'>"
+ "<query xmlns='jabber:iq:version'>&lt;query xmlns=&apos;jabber:iq:version&apos;/&gt;</query>"
+ "</iq>";

XmlPullParser parser = SmackTestUtil.getParserFor(iqXml, "iq", parserKind);
IQ iq = PacketParserUtils.parseIQ(parser);
assertXmlSimilar(expected, iq.toXML());
}
}

0 comments on commit 609781b

Please sign in to comment.