From 2900c5ae234345160e197835545c6cdfc3c4a215 Mon Sep 17 00:00:00 2001 From: asokolov Date: Wed, 14 Nov 2018 13:36:10 +0300 Subject: [PATCH] Move xml-not-well-formed (RFC 3920) condition handling to StreamError Fixes SMACK-842. --- .../jivesoftware/smack/packet/StanzaError.java | 5 ----- .../jivesoftware/smack/packet/StreamError.java | 5 +++++ .../smack/packet/StreamErrorTest.java | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/StanzaError.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/StanzaError.java index 6ebd523ab..fad9f5253 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/StanzaError.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/StanzaError.java @@ -385,11 +385,6 @@ public class StanzaError extends AbstractError implements ExtensionElement { } public static Condition fromString(String string) { - // Backwards compatibility for older implementations still using RFC 3920. RFC 6120 - // changed 'xml-not-well-formed' to 'not-well-formed'. - if ("xml-not-well-formed".equals(string)) { - string = "not-well-formed"; - } string = string.replace('-', '_'); Condition condition = null; try { diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/StreamError.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/StreamError.java index def48dfbe..67ec3ec2a 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/StreamError.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/StreamError.java @@ -186,6 +186,11 @@ public class StreamError extends AbstractError implements Nonza { } public static Condition fromString(String string) { + // Backwards compatibility for older implementations still using RFC 3920. RFC 6120 + // changed 'xml-not-well-formed' to 'not-well-formed'. + if ("xml-not-well-formed".equals(string)) { + string = "not-well-formed"; + } string = string.replace('-', '_'); Condition condition = null; try { diff --git a/smack-core/src/test/java/org/jivesoftware/smack/packet/StreamErrorTest.java b/smack-core/src/test/java/org/jivesoftware/smack/packet/StreamErrorTest.java index f390497f5..515053714 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/packet/StreamErrorTest.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/packet/StreamErrorTest.java @@ -104,4 +104,22 @@ public class StreamErrorTest { assertNotNull(appSpecificElement); } + @Test + public void testStreamErrorXmlNotWellFormed() { + StreamError error = null; + final String xml = + // Usually the stream:stream element has more attributes (to, version, ...) + // We omit those, since they are not relevant for testing + "" + + "" + + ""; + try { + XmlPullParser parser = PacketParserUtils.getParserFor(xml, "error"); + error = PacketParserUtils.parseStreamError(parser); + } catch (Exception e) { + fail(e.getMessage()); + } + assertNotNull(error); + assertEquals(Condition.not_well_formed, error.getCondition()); + } }