Merge pull request #4300 from eclipse/jetty-9.4.x-4296-websocketclient-double-decode
Fixes #4296 - WebSocketClient cannot connect with "%25" in query
This commit is contained in:
commit
9c9e842cd7
|
@ -25,6 +25,8 @@ import java.net.ServerSocket;
|
|||
import java.net.SocketTimeoutException;
|
||||
import java.net.URI;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
@ -174,6 +176,27 @@ public class ClientConnectTest
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpgradeRequest_PercentEncodedQuery() throws Exception
|
||||
{
|
||||
CloseTrackingEndpoint cliSock = new CloseTrackingEndpoint();
|
||||
client.getPolicy().setIdleTimeout(10000);
|
||||
|
||||
URI wsUri = WSURI.toWebsocket(server.getURI().resolve("/echo?name=%25foo"));
|
||||
ClientUpgradeRequest request = new ClientUpgradeRequest();
|
||||
request.setSubProtocols("echo");
|
||||
Future<Session> future = client.connect(cliSock, wsUri);
|
||||
|
||||
try (Session sess = future.get(30, TimeUnit.SECONDS))
|
||||
{
|
||||
assertThat("Connect.UpgradeRequest", sess.getUpgradeRequest(), notNullValue());
|
||||
Map<String, List<String>> paramMap = sess.getUpgradeRequest().getParameterMap();
|
||||
List<String> values = paramMap.get("name");
|
||||
assertThat("Params[name]", values.get(0), is("%foo"));
|
||||
assertThat("Connect.UpgradeResponse", sess.getUpgradeResponse(), notNullValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAltConnect() throws Exception
|
||||
{
|
||||
|
|
|
@ -152,19 +152,19 @@ public class ClientUpgradeRequest extends UpgradeRequestAdapter
|
|||
// parse parameter map
|
||||
Map<String, List<String>> pmap = new HashMap<>();
|
||||
|
||||
String query = uri.getQuery();
|
||||
String query = uri.getRawQuery();
|
||||
|
||||
if (StringUtil.isNotBlank(query))
|
||||
{
|
||||
MultiMap<String> params = new MultiMap<String>();
|
||||
UrlEncoded.decodeTo(uri.getQuery(), params, StandardCharsets.UTF_8);
|
||||
MultiMap<String> params = new MultiMap<>();
|
||||
UrlEncoded.decodeTo(query, params, StandardCharsets.UTF_8);
|
||||
|
||||
for (String key : params.keySet())
|
||||
{
|
||||
List<String> values = params.getValues(key);
|
||||
if (values == null)
|
||||
{
|
||||
pmap.put(key, new ArrayList<String>());
|
||||
pmap.put(key, new ArrayList<>());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue