add tests for Util
This commit is contained in:
@@ -16,7 +16,6 @@ import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
public abstract class Socket extends Emitter {
|
||||
|
||||
private static final Logger logger = Logger.getLogger("engine.io-client:socket");
|
||||
@@ -520,9 +519,9 @@ public abstract class Socket extends Emitter {
|
||||
opts.secure = "https".equals(uri.getScheme()) || "wss".equals(uri.getScheme());
|
||||
opts.port = uri.getPort();
|
||||
|
||||
String query = uri.getQuery();
|
||||
String query = uri.getRawQuery();
|
||||
if (query != null) {
|
||||
opts.query = uri.getQuery();
|
||||
opts.query = query;
|
||||
}
|
||||
|
||||
return opts;
|
||||
|
||||
@@ -15,12 +15,8 @@ public class Util {
|
||||
StringBuilder str = new StringBuilder();
|
||||
for (Map.Entry<String, String> entry : obj.entrySet()) {
|
||||
if (str.length() > 0) str.append("&");
|
||||
try {
|
||||
str.append(URLEncoder.encode(entry.getKey(), "UTF-8")).append("=")
|
||||
.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
str.append(encodeURIComponent(entry.getKey())).append("=")
|
||||
.append(encodeURIComponent(entry.getValue()));
|
||||
}
|
||||
return str.toString();
|
||||
}
|
||||
@@ -30,14 +26,31 @@ public class Util {
|
||||
String[] pairs = qs.split("&");
|
||||
for (String _pair : pairs) {
|
||||
String[] pair = _pair.split("=");
|
||||
try {
|
||||
qry.put(URLDecoder.decode(pair[0], "UTF-8"),
|
||||
pair.length > 0 ? URLDecoder.decode(pair[1], "UTF-8") : "");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
qry.put(decodeURIComponent(pair[0]),
|
||||
pair.length > 0 ? decodeURIComponent(pair[1]) : "");
|
||||
}
|
||||
return qry;
|
||||
}
|
||||
|
||||
public static String encodeURIComponent(String str) {
|
||||
try {
|
||||
return URLEncoder.encode(str, "UTF-8")
|
||||
.replace("+", "%20")
|
||||
.replace("%21", "!")
|
||||
.replace("%27", "'")
|
||||
.replace("%28", "(")
|
||||
.replace("%29", ")")
|
||||
.replace("%7E", "~");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String decodeURIComponent(String str) {
|
||||
try {
|
||||
return URLDecoder.decode(str, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user