You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by mo...@apache.org on 2021/03/10 21:13:05 UTC
[knox] branch master updated: KNOX-2475: url creation failure
caused by spaces in url (#408)
This is an automated email from the ASF dual-hosted git repository.
more pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git
The following commit(s) were added to refs/heads/master by this push:
new 9e2ce5e KNOX-2475: url creation failure caused by spaces in url (#408)
9e2ce5e is described below
commit 9e2ce5e6f6b517203741529f9ea014fcb5bb87d0
Author: yangxuxiang <71...@users.noreply.github.com>
AuthorDate: Thu Mar 11 05:12:56 2021 +0800
KNOX-2475: url creation failure caused by spaces in url (#408)
KNOX-2475: url creation failure caused by spaces in url
---
.../gateway/dispatch/AbstractGatewayDispatch.java | 5 +++++
.../gateway/dispatch/ConfigurableDispatchTest.java | 21 +++++++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/AbstractGatewayDispatch.java b/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/AbstractGatewayDispatch.java
index ce2bbb3..8e6a40f 100644
--- a/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/AbstractGatewayDispatch.java
+++ b/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/AbstractGatewayDispatch.java
@@ -144,6 +144,11 @@ public abstract class AbstractGatewayDispatch implements Dispatch {
str.replace(pipe, pipe+1, "%7C");
pipe = str.indexOf("|", pipe+1);
}
+ int space = str.indexOf(" ");
+ while (space > -1) {
+ str.replace(space, space+1, "%20");
+ space = str.indexOf(" ", space+1);
+ }
int dq = str.indexOf("\"");
while (dq > -1) {
str.replace(dq, dq+1, "%22");
diff --git a/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/ConfigurableDispatchTest.java b/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/ConfigurableDispatchTest.java
index 954f229..c518f03 100644
--- a/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/ConfigurableDispatchTest.java
+++ b/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/ConfigurableDispatchTest.java
@@ -73,6 +73,16 @@ public class ConfigurableDispatchTest {
assertThat( uri.toASCIIString(), is( "http://test-host:42/test,path" ) );
path = "http://test-host:42/test%2Cpath";
+ query = "service_config_version_note.matches(Updated%20Kerberos-related%20configurations";
+ request = EasyMock.createNiceMock( HttpServletRequest.class );
+ EasyMock.expect( request.getRequestURI() ).andReturn( path ).anyTimes();
+ EasyMock.expect( request.getRequestURL() ).andReturn( new StringBuffer( path ) ).anyTimes();
+ EasyMock.expect( request.getQueryString() ).andReturn( query ).anyTimes();
+ EasyMock.replay( request );
+ uri = dispatch.getDispatchUrl( request );
+ assertThat( uri.toASCIIString(), is( "http://test-host:42/test%2Cpath?service_config_version_note.matches(Updated%20Kerberos-related%20configurations" ) );
+
+ path = "http://test-host:42/test%2Cpath";
request = EasyMock.createNiceMock( HttpServletRequest.class );
EasyMock.expect( request.getRequestURI() ).andReturn( path ).anyTimes();
EasyMock.expect( request.getRequestURL() ).andReturn( new StringBuffer( path ) ).anyTimes();
@@ -130,6 +140,17 @@ public class ConfigurableDispatchTest {
uri = dispatch.getDispatchUrl( request );
assertThat( uri.toASCIIString(), is( "http://test-host:42/test%2Cpath" ) );
+ // encoding in query %20 is not removed
+ path = "http://test-host:42/test%2Cpath";
+ query = "service_config_version_note.matches(Updated%20Kerberos-related%20configurations";
+ request = EasyMock.createNiceMock( HttpServletRequest.class );
+ EasyMock.expect( request.getRequestURI() ).andReturn( path ).anyTimes();
+ EasyMock.expect( request.getRequestURL() ).andReturn( new StringBuffer( path ) ).anyTimes();
+ EasyMock.expect( request.getQueryString() ).andReturn( query ).anyTimes();
+ EasyMock.replay( request );
+ uri = dispatch.getDispatchUrl( request );
+ assertThat( uri.toASCIIString(), is( "http://test-host:42/test%2Cpath?service_config_version_note.matches(Updated%20Kerberos-related%20configurations" ) );
+
// encoding in query string is removed
path = "http://test-host:42/test%2Cpath";
query = "test%26name=test%3Dvalue";