mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-26 14:02: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:
parent
43744eb09f
commit
d4147e012b
3 changed files with 44 additions and 41 deletions
|
@ -340,7 +340,9 @@ public class PacketParserUtils {
|
||||||
// Parse the error type.
|
// Parse the error type.
|
||||||
XMPPError.Type errorType = XMPPError.Type.CANCEL;
|
XMPPError.Type errorType = XMPPError.Type.CANCEL;
|
||||||
try {
|
try {
|
||||||
errorType = XMPPError.Type.valueOf(type.toUpperCase());
|
if (type != null) {
|
||||||
|
errorType = XMPPError.Type.valueOf(type.toUpperCase());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException iae) {
|
catch (IllegalArgumentException iae) {
|
||||||
// Print stack trace. We shouldn't be getting an illegal error type.
|
// Print stack trace. We shouldn't be getting an illegal error type.
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class StringUtils {
|
||||||
if (XMPPAddress == null) {
|
if (XMPPAddress == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int atIndex = XMPPAddress.indexOf("@");
|
int atIndex = XMPPAddress.lastIndexOf("@");
|
||||||
if (atIndex <= 0) {
|
if (atIndex <= 0) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -68,13 +68,13 @@ public class StringUtils {
|
||||||
if (XMPPAddress == null) {
|
if (XMPPAddress == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int atIndex = XMPPAddress.indexOf("@");
|
int atIndex = XMPPAddress.lastIndexOf("@");
|
||||||
// If the String ends with '@', return the empty string.
|
// If the String ends with '@', return the empty string.
|
||||||
if (atIndex + 1 > XMPPAddress.length()) {
|
if (atIndex + 1 > XMPPAddress.length()) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
int slashIndex = XMPPAddress.indexOf("/");
|
int slashIndex = XMPPAddress.indexOf("/");
|
||||||
if (slashIndex > 0) {
|
if (slashIndex > 0 && slashIndex > atIndex) {
|
||||||
return XMPPAddress.substring(atIndex + 1, slashIndex);
|
return XMPPAddress.substring(atIndex + 1, slashIndex);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
package org.jivesoftware.smackx;
|
package org.jivesoftware.smackx;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.util.StringUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -33,6 +35,7 @@ import java.util.List;
|
||||||
* @author Gaston Dombiak
|
* @author Gaston Dombiak
|
||||||
*/
|
*/
|
||||||
public class FormField {
|
public class FormField {
|
||||||
|
|
||||||
public static final String TYPE_BOOLEAN = "boolean";
|
public static final String TYPE_BOOLEAN = "boolean";
|
||||||
public static final String TYPE_FIXED = "fixed";
|
public static final String TYPE_FIXED = "fixed";
|
||||||
public static final String TYPE_HIDDEN = "hidden";
|
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
|
* Creates a new FormField of type FIXED. The fields of type FIXED do not define a variable
|
||||||
* name.
|
* name.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public FormField() {
|
public FormField() {
|
||||||
this.type = FormField.TYPE_FIXED;
|
this.type = FormField.TYPE_FIXED;
|
||||||
|
@ -75,7 +77,7 @@ public class FormField {
|
||||||
* Returns a description that provides extra clarification about the question. This information
|
* 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
|
* could be presented to the user either in tool-tip, help button, or as a section of text
|
||||||
* before the question.<p>
|
* before the question.<p>
|
||||||
*
|
* <p/>
|
||||||
* If the question is of type FIXED then the description should remain empty.
|
* If the question is of type FIXED then the description should remain empty.
|
||||||
*
|
*
|
||||||
* @return description that provides extra clarification about the question.
|
* @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:
|
* Returns an indicative of the format for the data to answer. Valid formats are:
|
||||||
*
|
* <p/>
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>text-single -> single line or word of text
|
* <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-private -> instead of showing the user what they typed, you show ***** to
|
||||||
* protect it
|
* protect it
|
||||||
* <li>text-multi -> multiple lines of text entry
|
* <li>text-multi -> multiple lines of text entry
|
||||||
* <li>list-single -> given a list of choices, pick one
|
* <li>list-single -> given a list of choices, pick one
|
||||||
* <li>list-multi -> given a list of choices, pick one or more
|
* <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>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>fixed -> fixed for putting in text to show sections, or just advertise your web
|
||||||
* site in the middle of the form
|
* site in the middle of the form
|
||||||
* <li>hidden -> is not given to the user at all, but returned with the questionnaire
|
* <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>jid-single -> Jabber ID - choosing a JID from your roster, and entering one based
|
||||||
* on the rules for a JID.
|
* on the rules for a JID.
|
||||||
* <li>jid-multi -> multiple entries for JIDs
|
* <li>jid-multi -> multiple entries for JIDs
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @return format for the data to answer.
|
* @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
|
* 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
|
* could be presented to the user either in tool-tip, help button, or as a section of text
|
||||||
* before the question.<p>
|
* before the question.<p>
|
||||||
*
|
* <p/>
|
||||||
* If the question is of type FIXED then the description should remain empty.
|
* If the question is of type FIXED then the description should remain empty.
|
||||||
*
|
*
|
||||||
* @param description provides extra clarification about the question.
|
* @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:
|
* Sets an indicative of the format for the data to answer. Valid formats are:
|
||||||
*
|
* <p/>
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>text-single -> single line or word of text
|
* <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-private -> instead of showing the user what they typed, you show ***** to
|
||||||
* protect it
|
* protect it
|
||||||
* <li>text-multi -> multiple lines of text entry
|
* <li>text-multi -> multiple lines of text entry
|
||||||
* <li>list-single -> given a list of choices, pick one
|
* <li>list-single -> given a list of choices, pick one
|
||||||
* <li>list-multi -> given a list of choices, pick one or more
|
* <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>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>fixed -> fixed for putting in text to show sections, or just advertise your web
|
||||||
* site in the middle of the form
|
* site in the middle of the form
|
||||||
* <li>hidden -> is not given to the user at all, but returned with the questionnaire
|
* <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>jid-single -> Jabber ID - choosing a JID from your roster, and entering one based
|
||||||
* on the rules for a JID.
|
* on the rules for a JID.
|
||||||
* <li>jid-multi -> multiple entries for JIDs
|
* <li>jid-multi -> multiple entries for JIDs
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @param type an indicative of the format for the data to answer.
|
* @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.
|
* Removes all the values of the field.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
protected void resetValues() {
|
protected void resetValues() {
|
||||||
synchronized (values) {
|
synchronized (values) {
|
||||||
|
@ -292,19 +293,19 @@ public class FormField {
|
||||||
}
|
}
|
||||||
// Loop through all the values and append them to the string buffer
|
// Loop through all the values and append them to the string buffer
|
||||||
for (Iterator i = getOptions(); i.hasNext();) {
|
for (Iterator i = getOptions(); i.hasNext();) {
|
||||||
buf.append(((Option)i.next()).toXML());
|
buf.append(((Option) i.next()).toXML());
|
||||||
}
|
}
|
||||||
buf.append("</field>");
|
buf.append("</field>");
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Represents the available option of a given FormField.
|
* Represents the available option of a given FormField.
|
||||||
*
|
*
|
||||||
* @author Gaston Dombiak
|
* @author Gaston Dombiak
|
||||||
*/
|
*/
|
||||||
public static class Option {
|
public static class Option {
|
||||||
|
|
||||||
private String label;
|
private String label;
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
|
@ -335,7 +336,7 @@ public class FormField {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString(){
|
public String toString() {
|
||||||
return getLabel();
|
return getLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,7 +349,7 @@ public class FormField {
|
||||||
}
|
}
|
||||||
buf.append(">");
|
buf.append(">");
|
||||||
// Add element
|
// Add element
|
||||||
buf.append("<value>").append(getValue()).append("</value>");
|
buf.append("<value>").append(StringUtils.escapeForXML(getValue())).append("</value>");
|
||||||
|
|
||||||
buf.append("</option>");
|
buf.append("</option>");
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
|
|
Loading…
Reference in a new issue