mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-12-23 21:17:58 +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:
parent
43744eb09f
commit
d4147e012b
3 changed files with 44 additions and 41 deletions
|
@ -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.
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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,21 +119,21 @@ 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
|
||||
* <li>text-single -> single line or word of text
|
||||
* <li>text-private -> instead of showing the user what they typed, you show ***** to
|
||||
* protect it
|
||||
* <li>text-multi -> multiple lines of text entry
|
||||
* <li>list-single -> given a list of choices, pick one
|
||||
* <li>list-multi -> given a list of choices, pick one or more
|
||||
* <li>boolean -> 0 or 1, true or false, yes or no. Default value is 0
|
||||
* <li>fixed -> fixed for putting in text to show sections, or just advertise your web
|
||||
* <li>text-multi -> multiple lines of text entry
|
||||
* <li>list-single -> given a list of choices, pick one
|
||||
* <li>list-multi -> given a list of choices, pick one or more
|
||||
* <li>boolean -> 0 or 1, true or false, yes or no. Default value is 0
|
||||
* <li>fixed -> fixed for putting in text to show sections, or just advertise your web
|
||||
* site in the middle of the form
|
||||
* <li>hidden -> is not given to the user at all, but returned with the questionnaire
|
||||
* <li>jid-single -> Jabber ID - choosing a JID from your roster, and entering one based
|
||||
* <li>hidden -> is not given to the user at all, but returned with the questionnaire
|
||||
* <li>jid-single -> Jabber ID - choosing a JID from your roster, and entering one based
|
||||
* on the rules for a JID.
|
||||
* <li>jid-multi -> multiple entries for JIDs
|
||||
* <li>jid-multi -> multiple entries for JIDs
|
||||
* </ul>
|
||||
*
|
||||
* @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.<p>
|
||||
*
|
||||
* <p/>
|
||||
* 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:
|
||||
*
|
||||
* <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
|
||||
* <li>text-single -> single line or word of text
|
||||
* <li>text-private -> instead of showing the user what they typed, you show ***** to
|
||||
* protect it
|
||||
* <li>text-multi -> multiple lines of text entry
|
||||
* <li>list-single -> given a list of choices, pick one
|
||||
* <li>list-multi -> given a list of choices, pick one or more
|
||||
* <li>boolean -> 0 or 1, true or false, yes or no. Default value is 0
|
||||
* <li>fixed -> fixed for putting in text to show sections, or just advertise your web
|
||||
* <li>text-multi -> multiple lines of text entry
|
||||
* <li>list-single -> given a list of choices, pick one
|
||||
* <li>list-multi -> given a list of choices, pick one or more
|
||||
* <li>boolean -> 0 or 1, true or false, yes or no. Default value is 0
|
||||
* <li>fixed -> fixed for putting in text to show sections, or just advertise your web
|
||||
* site in the middle of the form
|
||||
* <li>hidden -> is not given to the user at all, but returned with the questionnaire
|
||||
* <li>jid-single -> Jabber ID - choosing a JID from your roster, and entering one based
|
||||
* <li>hidden -> is not given to the user at all, but returned with the questionnaire
|
||||
* <li>jid-single -> Jabber ID - choosing a JID from your roster, and entering one based
|
||||
* on the rules for a JID.
|
||||
* <li>jid-multi -> multiple entries for JIDs
|
||||
* <li>jid-multi -> multiple entries for JIDs
|
||||
* </ul>
|
||||
*
|
||||
* @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("</field>");
|
||||
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("<value>").append(getValue()).append("</value>");
|
||||
buf.append("<value>").append(StringUtils.escapeForXML(getValue())).append("</value>");
|
||||
|
||||
buf.append("</option>");
|
||||
return buf.toString();
|
||||
|
|
Loading…
Reference in a new issue