Incorrect xml representation of UnparsedIQ

Hello!

I’ve recently faced an issue of incorrect xml from UnparsedIQ. All my thoughts in one unit test:

import org.jivesoftware.smack.Smack;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.junit.Assert;
import org.junit.Test;

public class PacketParserUtilsTest {
    @Test
    public void unparsedIq() throws Exception {
        System.out.println(Smack.getVersion()); // 4.4.2 (4.4.2 2021-03-25)
        String control = "<iq " +
                "  xmlns='jabber:client'" +
                "  type='result'" +
                ">" +
                "  <unknown/>" +
                "</iq>\"";

        Stanza message = PacketParserUtils.parseStanza(control);
        String xml = message.toXML().toString(); // <iq xmlns='jabber:client' type='result'><unknown xmlns='jabber:client'&lt;unknown/&gt;</unknown></iq>
        Assert.assertEquals("<iq xmlns='jabber:client' type='result'>&lt;unknown/&gt;</iq>", xml);
    }
}

I think, that unparsed content should be escaped and put as content of IQ tag. For now, UnparsedIQ.toXml returns an XML that won’t be parsed because of errors in XML syntax.

Thanks for your feedback. It is very well possible that there is room for improvement of UnparsedIQ.

Not sure if this is what you are saying, but I believe that ideally

assertXmlSimilar(control, message.toXML().toString()

would hold.

If this is not the case, then patches towards this are welcome. :slight_smile:

It is not. Because parsed stanza has UnparsedIQ class, and toXml method must returns an XML which shows that it’s unparsed xml.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.