mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-12-24 05:27:56 +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,8 +340,10 @@ 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 {
|
||||||
|
if (type != null) {
|
||||||
errorType = XMPPError.Type.valueOf(type.toUpperCase());
|
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.
|
||||||
iae.printStackTrace();
|
iae.printStackTrace();
|
||||||
|
|
|
@ -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,7 +119,7 @@ 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
|
||||||
|
@ -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,7 +198,7 @@ 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
|
||||||
|
@ -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) {
|
||||||
|
@ -299,12 +300,12 @@ public class FormField {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* 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;
|
||||||
|
|
||||||
|
@ -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