From 50500ac99d139cecfa8f34e0094866d8efd76423 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 24 May 2017 23:03:22 +0200 Subject: [PATCH] Issue #1568 handle query strings with encoded characters --- .../jetty/websocket/api/util/WSURI.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/util/WSURI.java b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/util/WSURI.java index 57f9c075fba..3c904b37678 100644 --- a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/util/WSURI.java +++ b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/util/WSURI.java @@ -45,7 +45,7 @@ public final class WSURI if ("http".equalsIgnoreCase(wsScheme) || "https".equalsIgnoreCase(wsScheme)) { // leave alone - return inputUri; // TODO should this be cloned? + return new URI(inputUri.toString()); } if ("ws".equalsIgnoreCase(wsScheme)) @@ -117,26 +117,24 @@ public final class WSURI { Objects.requireNonNull(inputUri,"Input URI must not be null"); String httpScheme = inputUri.getScheme(); - String wsScheme = null; if ("ws".equalsIgnoreCase(httpScheme) || "wss".equalsIgnoreCase(httpScheme)) { // keep as-is - wsScheme = httpScheme; + return new URI(inputUri.toString()); } - else if ("http".equalsIgnoreCase(httpScheme)) + + if ("http".equalsIgnoreCase(httpScheme)) { // convert to ws - wsScheme = "ws"; + return new URI("ws"+inputUri.toString().substring(4)); } - else if ("https".equalsIgnoreCase(httpScheme)) + + if ("https".equalsIgnoreCase(httpScheme)) { // convert to wss - wsScheme = "wss"; + return new URI("wss"+inputUri.toString().substring(5)); } - else - { - throw new URISyntaxException(inputUri.toString(),"Unrecognized HTTP scheme"); - } - return new URI(wsScheme,inputUri.getUserInfo(),inputUri.getHost(),inputUri.getPort(),inputUri.getPath(),inputUri.getQuery(),inputUri.getFragment()); + + throw new URISyntaxException(inputUri.toString(),"Unrecognized HTTP scheme"); } }