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

1) Escape values in form field to prevent error.

2) Check for null value in error type to handle invalid error types.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@5737 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Derek DeMoro 2006-10-17 13:15:35 +00:00 committed by derek
parent 43744eb09f
commit d4147e012b
3 changed files with 44 additions and 41 deletions

View file

@ -340,8 +340,10 @@ public class PacketParserUtils {
// Parse the error type.
XMPPError.Type errorType = XMPPError.Type.CANCEL;
try {
if (type != null) {
errorType = XMPPError.Type.valueOf(type.toUpperCase());
}
}
catch (IllegalArgumentException iae) {
// Print stack trace. We shouldn't be getting an illegal error type.
iae.printStackTrace();

View file

@ -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 {

View file

@ -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.<p>
*
* <p/>
* If the question is of type FIXED then the description should remain empty.
*
* @return description that provides extra clarification about the question.
@ -117,7 +119,7 @@ public class FormField {
/**
* Returns an indicative of the format for the data to answer. Valid formats are:
*
* <p/>
* <ul>
* <li>text-single -> single line or word of text
* <li>text-private -> instead of showing the user what they typed, you show ***** to
@ -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.<p>
*
* <p/>
* If the question is of type FIXED then the description should remain empty.
*
* @param description provides extra clarification about the question.
@ -196,7 +198,7 @@ public class FormField {
/**
* Sets an indicative of the format for the data to answer. Valid formats are:
*
* <p/>
* <ul>
* <li>text-single -> single line or word of text
* <li>text-private -> instead of showing the user what they typed, you show ***** to
@ -245,7 +247,6 @@ public class FormField {
/**
* Removes all the values of the field.
*
*/
protected void resetValues() {
synchronized (values) {
@ -292,19 +293,19 @@ 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("</field>");
return buf.toString();
}
/**
*
* Represents the available option of a given FormField.
*
* @author Gaston Dombiak
*/
public static class Option {
private String label;
private String value;
@ -335,7 +336,7 @@ public class FormField {
return value;
}
public String toString(){
public String toString() {
return getLabel();
}
@ -348,7 +349,7 @@ public class FormField {
}
buf.append(">");
// Add element
buf.append("<value>").append(getValue()).append("</value>");
buf.append("<value>").append(StringUtils.escapeForXML(getValue())).append("</value>");
buf.append("</option>");
return buf.toString();