diff --git a/source/org/jivesoftware/smack/util/PacketParserUtils.java b/source/org/jivesoftware/smack/util/PacketParserUtils.java index 66332d071..8bc8049b7 100644 --- a/source/org/jivesoftware/smack/util/PacketParserUtils.java +++ b/source/org/jivesoftware/smack/util/PacketParserUtils.java @@ -340,7 +340,9 @@ public class PacketParserUtils { // Parse the error type. XMPPError.Type errorType = XMPPError.Type.CANCEL; try { - errorType = XMPPError.Type.valueOf(type.toUpperCase()); + if (type != null) { + errorType = XMPPError.Type.valueOf(type.toUpperCase()); + } } catch (IllegalArgumentException iae) { // Print stack trace. We shouldn't be getting an illegal error type. diff --git a/source/org/jivesoftware/smack/util/StringUtils.java b/source/org/jivesoftware/smack/util/StringUtils.java index b2248c05d..2be51ecf3 100644 --- a/source/org/jivesoftware/smack/util/StringUtils.java +++ b/source/org/jivesoftware/smack/util/StringUtils.java @@ -47,7 +47,7 @@ public class StringUtils { if (XMPPAddress == null) { return null; } - int atIndex = XMPPAddress.indexOf("@"); + int atIndex = XMPPAddress.lastIndexOf("@"); if (atIndex <= 0) { return ""; } @@ -68,13 +68,13 @@ public class StringUtils { if (XMPPAddress == null) { return null; } - int atIndex = XMPPAddress.indexOf("@"); + int atIndex = XMPPAddress.lastIndexOf("@"); // If the String ends with '@', return the empty string. if (atIndex + 1 > XMPPAddress.length()) { return ""; } int slashIndex = XMPPAddress.indexOf("/"); - if (slashIndex > 0) { + if (slashIndex > 0 && slashIndex > atIndex) { return XMPPAddress.substring(atIndex + 1, slashIndex); } else { diff --git a/source/org/jivesoftware/smackx/FormField.java b/source/org/jivesoftware/smackx/FormField.java index 84432914a..3df05d0a5 100644 --- a/source/org/jivesoftware/smackx/FormField.java +++ b/source/org/jivesoftware/smackx/FormField.java @@ -20,6 +20,8 @@ package org.jivesoftware.smackx; +import org.jivesoftware.smack.util.StringUtils; + import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -33,6 +35,7 @@ import java.util.List; * @author Gaston Dombiak */ public class FormField { + public static final String TYPE_BOOLEAN = "boolean"; public static final String TYPE_FIXED = "fixed"; public static final String TYPE_HIDDEN = "hidden"; @@ -65,7 +68,6 @@ public class FormField { /** * Creates a new FormField of type FIXED. The fields of type FIXED do not define a variable * name. - * */ public FormField() { this.type = FormField.TYPE_FIXED; @@ -75,7 +77,7 @@ public class FormField { * Returns a description that provides extra clarification about the question. This information * could be presented to the user either in tool-tip, help button, or as a section of text * before the question.

- * + *

* If the question is of type FIXED then the description should remain empty. * * @return description that provides extra clarification about the question. @@ -117,21 +119,21 @@ public class FormField { /** * Returns an indicative of the format for the data to answer. Valid formats are: - * + *

*

* * @return format for the data to answer. @@ -166,7 +168,7 @@ public class FormField { * Sets a description that provides extra clarification about the question. This information * could be presented to the user either in tool-tip, help button, or as a section of text * before the question.

- * + *

* If the question is of type FIXED then the description should remain empty. * * @param description provides extra clarification about the question. @@ -196,21 +198,21 @@ public class FormField { /** * Sets an indicative of the format for the data to answer. Valid formats are: - * + *

*

* * @param type an indicative of the format for the data to answer. @@ -245,7 +247,6 @@ public class FormField { /** * Removes all the values of the field. - * */ protected void resetValues() { synchronized (values) { @@ -292,21 +293,21 @@ public class FormField { } // Loop through all the values and append them to the string buffer for (Iterator i = getOptions(); i.hasNext();) { - buf.append(((Option)i.next()).toXML()); + buf.append(((Option) i.next()).toXML()); } buf.append(""); return buf.toString(); } /** - * - * Represents the available option of a given FormField. - * + * Represents the available option of a given FormField. + * * @author Gaston Dombiak */ public static class Option { + private String label; - private String value; + private String value; public Option(String value) { this.value = value; @@ -316,10 +317,10 @@ public class FormField { this.label = label; this.value = value; } - + /** - * Returns the label that represents the option. - * + * Returns the label that represents the option. + * * @return the label that represents the option. */ public String getLabel() { @@ -328,14 +329,14 @@ public class FormField { /** * Returns the value of the option. - * + * * @return the value of the option. */ public String getValue() { return value; } - public String toString(){ + public String toString() { return getLabel(); } @@ -348,7 +349,7 @@ public class FormField { } buf.append(">"); // Add element - buf.append("").append(getValue()).append(""); + buf.append("").append(StringUtils.escapeForXML(getValue())).append(""); buf.append(""); return buf.toString();