powered by Jive Software

XHTML Receiving Messages Bug (with patch!)

Hi,

I’'ve discovered a bug in Smack. When receiving XHTML messages, Smack decodes the entities in the message, generating potentally invalid XML and making reconstruction impossible.

For example: I received a message containing:

bi bo bu

When I call getBodies().next(), I receive the following string:

bi bu

I isolated a fix and generated a patch (it’'s basically just a string search/replace):

— source/org/jivesoftware/smackx/provider/XHTMLExtensionProvider.java 2006-06-12 23:13:14.000000000 +0200

+++ …/smack-dev-2.2.1_fixed/source/org/jivesoftware/smackx/provider/XHTMLExtension Provider.java 2006-06-21 16:26:02.000000000 +0200

@@ -43,29 +43,47 @@

  • Parses a XHTMLExtension packet (extension sub-packet).
  • @param parser the XML parser, positioned at the starting element of the extension.

  • @return a PacketExtension.

  • @throws Exception if a parsing error occurs.

*/

public PacketExtension parseExtension(XmlPullParser parser)

throws Exception {

XHTMLExtension xhtmlExtension = new XHTMLExtension();

boolean done = false;

StringBuffer buffer = new StringBuffer();;

while (!done) {

int eventType = parser.next();

if (eventType == XmlPullParser.START_TAG) {

if (parser.getName().equals(“body”))

buffer = new StringBuffer();

buffer.append(parser.getText());

} else if (eventType == XmlPullParser.TEXT) {

  •            if (buffer != null) buffer.append(parser.getText());
    
  •            StringBuffer text = new StringBuffer(parser.getText());
    
  •            int loc = 0;
    
  •            while((loc = text.indexOf("&",loc)) != -1) {
    
  •                text.replace(loc,loc+1,"&");
    
  •                loc += 4;
    
  •            }
    
  •            loc = 0;
    
  •            while((loc = text.indexOf("<",loc)) != -1) {
    
  •                text.replace(loc,loc+1,"&lt;");
    
  •                loc += 3;
    
  •            }
    
  •            loc = 0;
    
  •            while((loc = text.indexOf(">",loc)) != -1) {
    
  •                text.replace(loc,loc+1,"&gt;");
    
  •                loc += 3;
    
  •            }
    
  •            if (buffer != null) buffer.append(text);
    

} else if (eventType == XmlPullParser.END_TAG) {

if (parser.getName().equals(“body”)) {

buffer.append(parser.getText());

xhtmlExtension.addBody(buffer.toString());

}

else if (parser.getName().equals(xhtmlExtension.getElementName())) {

done = true;

}

else

buffer.append(parser.getText());

(I’'m sorry for the formatting)

Message was edited by: AWenckus

Thanks! This issue has been filed as SMACK-145.

Regards,

Matt