Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Augé2020-05-05 20:34:38 +0000
committerThomas Watson2020-05-05 21:31:55 +0000
commit9a0d95dd4a5d08977564f4ca5930b5570bccdc8d (patch)
tree7eb1757d1badfeaef39cf9737116cc3c31fb6b7b
parent0db7ceaf4e4d0cbbfe1481069fa7af78203f1836 (diff)
downloadrt.equinox.bundles-9a0d95dd4a5d08977564f4ca5930b5570bccdc8d.tar.gz
rt.equinox.bundles-9a0d95dd4a5d08977564f4ca5930b5570bccdc8d.tar.xz
rt.equinox.bundles-9a0d95dd4a5d08977564f4ca5930b5570bccdc8d.zip
Bug 562843 - Invalid behavior in HttpServletRequest methods with respectI20200511-0700I20200510-1800I20200509-1800I20200509-0600I20200509-0450I20200506-1800
to URI encoding Change-Id: I54237e224a22ceafe6b3cd7b66e602c12899558c Signed-off-by: Raymond Augé <raymond.auge@liferay.com>
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/testbase/AllTests.java4
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/Bug562843_Test.java50
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceRuntimeImpl.java20
3 files changed, 69 insertions, 5 deletions
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/testbase/AllTests.java b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/testbase/AllTests.java
index 64a3c7722..60bfe3428 100644
--- a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/testbase/AllTests.java
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/testbase/AllTests.java
@@ -15,6 +15,7 @@ package org.eclipse.equinox.http.servlet.testbase;
import org.eclipse.equinox.http.servlet.tests.AuthenticationTest;
import org.eclipse.equinox.http.servlet.tests.Bug500783_Test;
+import org.eclipse.equinox.http.servlet.tests.Bug562843_Test;
import org.eclipse.equinox.http.servlet.tests.ContextHelperCustomizerTests;
import org.eclipse.equinox.http.servlet.tests.DispatchingTest;
import org.eclipse.equinox.http.servlet.tests.PreprocessorTestCase;
@@ -96,7 +97,8 @@ import org.junit.runners.Suite.SuiteClasses;
TestHttpServiceAndNamedServlet.class,
TestUpload.class,
ContextHelperCustomizerTests.class,
- Bug500783_Test.class
+ Bug500783_Test.class,
+ Bug562843_Test.class
})
public class AllTests {
// see @SuiteClasses
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/Bug562843_Test.java b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/Bug562843_Test.java
new file mode 100644
index 000000000..8cc2a8a11
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/Bug562843_Test.java
@@ -0,0 +1,50 @@
+package org.eclipse.equinox.http.servlet.tests;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.concurrent.atomic.AtomicReference;
+
+import javax.servlet.Servlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.equinox.http.servlet.testbase.BaseTest;
+import org.junit.Assert;
+import org.junit.Test;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
+
+public class Bug562843_Test extends BaseTest {
+
+ @Test
+ public void test_Bug562843() throws Exception {
+ final AtomicReference<String> requestURI = new AtomicReference<>();
+ final AtomicReference<String> servletPath = new AtomicReference<>();
+ final AtomicReference<String> pathInfo = new AtomicReference<>();
+ Servlet servlet = new HttpServlet() {
+ private static final long serialVersionUID = 1L;
+ @Override
+ protected void doGet(
+ final HttpServletRequest req, final HttpServletResponse resp)
+ throws IOException {
+ requestURI.set(req.getRequestURI());
+ servletPath.set(req.getServletPath());
+ pathInfo.set(req.getPathInfo());
+ PrintWriter writer = resp.getWriter();
+ writer.write("OK");
+ }
+ };
+ Dictionary<String, Object> props = new Hashtable<>();
+ props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "Bug 562843");
+ props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/Bug 562843/*");
+ registrations.add(getBundleContext().registerService(Servlet.class, servlet, props));
+ String result = requestAdvisor.request("Bug%20562843/a%20b%20c");
+ Assert.assertEquals("OK", result);
+ Assert.assertEquals("/Bug%20562843/a%20b%20c", requestURI.get());
+ Assert.assertEquals("/Bug 562843", servletPath.get());
+ Assert.assertEquals("/a b c", pathInfo.get());
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceRuntimeImpl.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceRuntimeImpl.java
index 8d07030b8..872fa055f 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceRuntimeImpl.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceRuntimeImpl.java
@@ -18,6 +18,9 @@ import static org.osgi.service.http.runtime.HttpServiceRuntimeConstants.HTTP_SER
import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.*;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.*;
@@ -511,7 +514,7 @@ public class HttpServiceRuntimeImpl
int pos = requestURI.lastIndexOf('/');
- String servletPath = requestURI;
+ String servletPath = decode(requestURI);
String pathInfo = null;
if (match == Match.CONTEXT_ROOT) {
@@ -537,8 +540,8 @@ public class HttpServiceRuntimeImpl
if (pos > -1) {
String newServletPath = requestURI.substring(0, pos);
- pathInfo = requestURI.substring(pos);
- servletPath = newServletPath;
+ pathInfo = decode(requestURI.substring(pos));
+ servletPath = decode(newServletPath);
pos = servletPath.lastIndexOf('/');
continue;
@@ -1092,7 +1095,7 @@ public class HttpServiceRuntimeImpl
sb.append("(objectClass=").append(HttpSessionListener.class.getName()).append(")"); //$NON-NLS-1$ //$NON-NLS-2$
sb.append("(objectClass=").append(HttpSessionAttributeListener.class.getName()).append(")"); //$NON-NLS-1$ //$NON-NLS-2$
if ((servletContext.getMajorVersion() >= 3) && (servletContext.getMinorVersion() > 0)) {
- sb.append("(objectClass=").append(HttpSessionIdListener.class.getName()).append(")"); //$NON-NLS-1$ //$NON-NLS-2$
+ sb.append("(objectClass=").append(HttpSessionIdListener.class.getName()).append(")"); //$NON-NLS-1$ //$NON-NLS-2$
}
sb.append(")"); //$NON-NLS-1$
sb.append(")"); //$NON-NLS-1$
@@ -1281,6 +1284,15 @@ public class HttpServiceRuntimeImpl
return semaphore;
}
+ private String decode(String urlEncoded) {
+ try {
+ return URLDecoder.decode(urlEncoded, StandardCharsets.UTF_8.name());
+ }
+ catch (UnsupportedEncodingException e) {
+ return urlEncoded;
+ }
+ }
+
private final Map<String, Object> attributes;
private final String targetFilter;
final ServiceRegistration<ServletContextHelper> defaultContextReg;

Back to the top