From eb9242768cf5e3d9007f0485b972bb62a084e535 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sat, 12 Nov 2016 23:34:02 +0100 Subject: [PATCH] Throw exception if stanza child contains text --- .../java/org/jivesoftware/smack/util/PacketParserUtils.java | 6 ++++++ .../org/jivesoftware/smack/util/PacketParserUtilsTest.java | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java b/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java index e1aef4773..53d0428eb 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java @@ -289,6 +289,8 @@ public class PacketParserUtils { break outerloop; } break; + case XmlPullParser.TEXT: + throw new IllegalStateException("Invalid Stanza: Must not contain text or mixed content as direct child of "); } } @@ -589,6 +591,8 @@ public class PacketParserUtils { break outerloop; } break; + case XmlPullParser.TEXT: + throw new IllegalStateException("Invalid Stanza: Must not contain text or mixed content as direct child of "); } } return presence; @@ -645,6 +649,8 @@ public class PacketParserUtils { break outerloop; } break; + case XmlPullParser.TEXT: + throw new IllegalStateException("Invalid Stanza: Must not contain text or mixed content as direct child of "); } } // Decide what to do when an IQ packet was not understood diff --git a/smack-core/src/test/java/org/jivesoftware/smack/util/PacketParserUtilsTest.java b/smack-core/src/test/java/org/jivesoftware/smack/util/PacketParserUtilsTest.java index 117e9e3c1..e24196d15 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/util/PacketParserUtilsTest.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/util/PacketParserUtilsTest.java @@ -710,8 +710,8 @@ public class PacketParserUtilsTest { try { PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(invalidControl)); fail("Exception should be thrown"); - } catch(XmlPullParserException e) { - assertTrue(e.getMessage().contains("end tag name ")); + } catch(IllegalStateException e) { + assertTrue(e.getMessage().contains("Invalid Stanza")); } invalidControl = validControl.replace("Good Message Body", "Bad Body");