1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-29 23:42:06 +01:00

Throw exception if stanza child contains text

This commit is contained in:
Florian Schmaus 2016-11-12 23:34:02 +01:00
parent 5a47f56cd0
commit eb9242768c
2 changed files with 8 additions and 2 deletions

View file

@ -289,6 +289,8 @@ public class PacketParserUtils {
break outerloop; break outerloop;
} }
break; break;
case XmlPullParser.TEXT:
throw new IllegalStateException("Invalid Stanza: Must not contain text or mixed content as direct child of <message/>");
} }
} }
@ -589,6 +591,8 @@ public class PacketParserUtils {
break outerloop; break outerloop;
} }
break; break;
case XmlPullParser.TEXT:
throw new IllegalStateException("Invalid Stanza: Must not contain text or mixed content as direct child of <presence/>");
} }
} }
return presence; return presence;
@ -645,6 +649,8 @@ public class PacketParserUtils {
break outerloop; break outerloop;
} }
break; break;
case XmlPullParser.TEXT:
throw new IllegalStateException("Invalid Stanza: Must not contain text or mixed content as direct child of <iq/>");
} }
} }
// Decide what to do when an IQ packet was not understood // Decide what to do when an IQ packet was not understood

View file

@ -710,8 +710,8 @@ public class PacketParserUtilsTest {
try { try {
PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(invalidControl)); PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(invalidControl));
fail("Exception should be thrown"); fail("Exception should be thrown");
} catch(XmlPullParserException e) { } catch(IllegalStateException e) {
assertTrue(e.getMessage().contains("end tag name </body>")); assertTrue(e.getMessage().contains("Invalid Stanza"));
} }
invalidControl = validControl.replace("Good Message Body", "Bad </message> Body"); invalidControl = validControl.replace("Good Message Body", "Bad </message> Body");