* Decode and return the specified URL-encoded String.
* When the byte array is converted to a string, the system default
* character encoding is used... This may be different than some other
- * servers.
+ * servers. It is assumed the string is not a query string.
*
* @param str The url-encoded string
*
* by a valid 2-digit hexadecimal number
*/
public static String URLDecode(String str) {
-
return URLDecode(str, null);
-
}
-
-
+
+
/**
- * Decode and return the specified URL-encoded String.
+ * Decode and return the specified URL-encoded String. It is assumed the
+ * string is not a query string.
*
* @param str The url-encoded string
* @param enc The encoding to use; if null, the default encoding is used
* by a valid 2-digit hexadecimal number
*/
public static String URLDecode(String str, String enc) {
-
+ return URLDecode(str, enc, false);
+ }
+
+ /**
+ * Decode and return the specified URL-encoded String.
+ *
+ * @param str The url-encoded string
+ * @param enc The encoding to use; if null, the default encoding is used
+ * @param isQuery Is this a query string being processed
+ * @exception IllegalArgumentException if a '%' character is not followed
+ * by a valid 2-digit hexadecimal number
+ */
+ public static String URLDecode(String str, String enc, boolean isQuery) {
if (str == null)
return (null);
}
} catch (UnsupportedEncodingException uee) {}
- return URLDecode(bytes, enc);
+ return URLDecode(bytes, enc, isQuery);
}
/**
- * Decode and return the specified URL-encoded byte array.
+ * Decode and return the specified URL-encoded byte array. It is assumed
+ * the string is not a query string.
*
* @param bytes The url-encoded byte array
* @exception IllegalArgumentException if a '%' character is not followed
/**
- * Decode and return the specified URL-encoded byte array.
+ * Decode and return the specified URL-encoded byte array. It is assumed
+ * the string is not a query string.
*
* @param bytes The url-encoded byte array
* @param enc The encoding to use; if null, the default encoding is used
* by a valid 2-digit hexadecimal number
*/
public static String URLDecode(byte[] bytes, String enc) {
+ return URLDecode(bytes, null, false);
+ }
+ /**
+ * Decode and return the specified URL-encoded byte array.
+ *
+ * @param bytes The url-encoded byte array
+ * @param enc The encoding to use; if null, the default encoding is used
+ * @param isQuery Is this a query string being processed
+ * @exception IllegalArgumentException if a '%' character is not followed
+ * by a valid 2-digit hexadecimal number
+ */
+ public static String URLDecode(byte[] bytes, String enc, boolean isQuery) {
+
if (bytes == null)
return (null);
int ox = 0;
while (ix < len) {
byte b = bytes[ix++]; // Get byte to test
- if (b == '+') {
+ if (b == '+' && isQuery) {
b = (byte)' ';
} else if (b == '%') {
b = (byte) ((convertHexDigit(bytes[ix++]) << 4)