1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-26 00:02:06 +01:00

Set conditionText to null if it's the empty string

This fixes e.g. IllegalArgumentException "'conflict' can not contain a
condition text", when receiving elements like

<stream:error>
  <conflict xmlns='urn:ietf:params:xml:ns:xmpp-streams'></conflict>
  <text xml:lang='' xmlns='urn:ietf:params:xml:ns:xmpp-streams'>
    Replaced by new connection
  </text>
</sream:error>

(ejabberd does this)
This commit is contained in:
Florian Schmaus 2014-12-10 12:36:35 +01:00
parent c89d06861b
commit 7640414e8d
2 changed files with 14 additions and 0 deletions

View file

@ -20,6 +20,7 @@ package org.jivesoftware.smack.packet;
import java.util.List;
import java.util.Map;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.XmlStringBuilder;
/**
@ -105,6 +106,12 @@ public class StreamError extends AbstractError implements PlainStreamElement {
public StreamError(Condition condition, String conditionText, Map<String, String> descriptiveTexts, List<PacketExtension> extensions) {
super(descriptiveTexts, extensions);
// Some implementations may send the condition as non-empty element containing the empty string, that is
// <condition xmlns='foo'></condition>, in this case the parser may calls this constructor with the empty string
// as conditionText, therefore reset it to null if it's the empty string
if (StringUtils.isNullOrEmpty(conditionText)) {
conditionText = null;
}
if (conditionText != null) {
switch (condition) {
case see_other_host:

View file

@ -22,6 +22,7 @@ import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.XmlStringBuilder;
/**
@ -117,6 +118,12 @@ public class XMPPError extends AbstractError {
List<PacketExtension> extensions) {
super(descriptiveTexts, NAMESPACE, extensions);
this.condition = condition;
// Some implementations may send the condition as non-empty element containing the empty string, that is
// <condition xmlns='foo'></condition>, in this case the parser may calls this constructor with the empty string
// as conditionText, therefore reset it to null if it's the empty string
if (StringUtils.isNullOrEmpty(conditionText)) {
conditionText = null;
}
if (conditionText != null) {
switch (condition) {
case gone: