diff options
author | Raymond Auge | 2017-05-17 16:10:54 +0000 |
---|---|---|
committer | Raymond Auge | 2017-05-22 12:18:22 +0000 |
commit | 3eb1d9e3c39039085c5a6298eb6be6ae12c74760 (patch) | |
tree | b0630d32bd985b19884a45d8b6d78e1bf12e3c05 | |
parent | 927cab9342cf638300bfb284a6363bc284d8c5ec (diff) | |
download | rt.equinox.bundles-3eb1d9e3c39039085c5a6298eb6be6ae12c74760.tar.gz rt.equinox.bundles-3eb1d9e3c39039085c5a6298eb6be6ae12c74760.tar.xz rt.equinox.bundles-3eb1d9e3c39039085c5a6298eb6be6ae12c74760.zip |
Bug 497510 - [http] HttpServletRequestWrapperImpl::getRequestUri()
returning decoded URI
Change-Id: I602a0f316498f2876c121ed0c5d59e3216e3affd
Signed-off-by: Raymond Auge <raymond.auge@liferay.com>
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
6 files changed, 113 insertions, 7 deletions
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/DispatchingTest.java b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/DispatchingTest.java index c9a9990d2..a3711f5c9 100644 --- a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/DispatchingTest.java +++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/DispatchingTest.java @@ -1576,4 +1576,61 @@ public class DispatchingTest extends BaseTest { Assert.assertEquals(10, counter.get()); } + @Test + public void test_Bug497510_1() throws Exception { + Servlet servlet = new HttpServlet() { + private static final long serialVersionUID = 1L; + + @Override + protected void doGet( + final HttpServletRequest req, final HttpServletResponse resp) + throws ServletException, IOException { + + String requestURI = req.getRequestURI(); + + Assert.assertNotNull(requestURI); + + PrintWriter writer = resp.getWriter(); + writer.write(requestURI); + } + }; + + Dictionary<String, Object> props = new Hashtable<String, Object>(); + props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "Bug497510"); + props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/Bug497510/*"); + registrations.add(getBundleContext().registerService(Servlet.class, servlet, props)); + + String result = requestAdvisor.request("Bug497510/a%20b%20c"); + + Assert.assertEquals("/Bug497510/a%20b%20c", result); + } + + @Test + public void test_Bug497510_2() throws Exception { + Servlet servlet = new HttpServlet() { + private static final long serialVersionUID = 1L; + + @Override + protected void doGet( + final HttpServletRequest req, final HttpServletResponse resp) + throws ServletException, IOException { + + String requestURI = req.getRequestURI(); + + Assert.assertNotNull(requestURI); + + PrintWriter writer = resp.getWriter(); + writer.write(requestURI); + } + }; + + Dictionary<String, Object> props = new Hashtable<String, Object>(); + props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "Bug 497510"); + props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/Bug 497510/*"); + registrations.add(getBundleContext().registerService(Servlet.class, servlet, props)); + + String result = requestAdvisor.request("Bug%20497510/a%20b%20c"); + + Assert.assertEquals("/Bug%20497510/a%20b%20c", result); + } }
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/FilterRegistration.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/FilterRegistration.java index 27975ca81..5e68ec68b 100644 --- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/FilterRegistration.java +++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/FilterRegistration.java @@ -38,6 +38,7 @@ public class FilterRegistration private final ContextController contextController; private final boolean initDestoyWithContextController; private final Pattern[] compiledRegexs; + private final boolean needDecode; public FilterRegistration( ServiceHolder<Filter> filterHolder, FilterDTO filterDTO, int priority, @@ -70,6 +71,7 @@ public class FilterRegistration } else { initDestoyWithContextController = true; } + needDecode = MatchableRegistration.patternsRequireDecode(filterDTO.patterns); } public int compareTo(FilterRegistration otherFilterRegistration) { @@ -272,4 +274,9 @@ public class FilterRegistration return patterns; } + @Override + public boolean needDecode() { + return needDecode; + } + } diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/MatchableRegistration.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/MatchableRegistration.java index 941437885..4da830e57 100644 --- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/MatchableRegistration.java +++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/MatchableRegistration.java @@ -11,6 +11,9 @@ package org.eclipse.equinox.http.servlet.internal.registration; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.net.URLEncoder; import org.eclipse.equinox.http.servlet.internal.servlet.Match; import org.eclipse.equinox.http.servlet.internal.util.Const; import org.osgi.dto.DTO; @@ -25,12 +28,14 @@ public abstract class MatchableRegistration<T, D extends DTO> super(t, d); } + public abstract boolean needDecode(); + public abstract String match( String name, String servletPath, String pathInfo, String extension, Match match); - protected boolean isPathWildcardMatch( - String pattern, String servletPath, String pathInfo) { + private boolean isPathWildcardMatch( + String pattern, String servletPath) { int cpl = pattern.length() - 2; @@ -47,11 +52,18 @@ public abstract class MatchableRegistration<T, D extends DTO> return false; } - protected boolean doMatch( + final protected boolean doMatch( String pattern, String servletPath, String pathInfo, String extension, Match match) throws IllegalArgumentException { - + if (needDecode()) { + try { + servletPath = URLDecoder.decode(servletPath, "UTF-8"); //$NON-NLS-1$ + } + catch (UnsupportedEncodingException e) { + // do nothing + } + } if (match == Match.EXACT) { return pattern.equals(servletPath); } @@ -66,7 +78,7 @@ public abstract class MatchableRegistration<T, D extends DTO> } if ((match == Match.REGEX) && isPathWildcardMatch( - pattern, servletPath, pathInfo)) { + pattern, servletPath)) { return true; } @@ -88,4 +100,18 @@ public abstract class MatchableRegistration<T, D extends DTO> return false; } + static boolean patternsRequireDecode(String[] patterns) { + for (String pattern : patterns) { + try { + String encode = URLEncoder.encode(pattern, "UTF-8"); //$NON-NLS-1$ + if (!encode.equals(pattern)) { + return true; + } + } + catch (UnsupportedEncodingException e) { + // do nothing + } + } + return false; + } }
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ResourceRegistration.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ResourceRegistration.java index fc6ac646d..ff10f1bc4 100644 --- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ResourceRegistration.java +++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ResourceRegistration.java @@ -29,6 +29,7 @@ public class ResourceRegistration extends EndpointRegistration<ResourceDTO> { super(servletHolder, resourceDTO, servletContextHelper, contextController, legacyTCCL); name = servletHolder.get().getClass().getName().concat("#").concat(getD().prefix); //$NON-NLS-1$ + needDecode = MatchableRegistration.patternsRequireDecode(resourceDTO.patterns); } @Override @@ -46,6 +47,12 @@ public class ResourceRegistration extends EndpointRegistration<ResourceDTO> { return getD().serviceId; } + @Override + public boolean needDecode() { + return needDecode; + } + + private final boolean needDecode; private final String name; } diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ServletRegistration.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ServletRegistration.java index 63267f9e5..be982f459 100644 --- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ServletRegistration.java +++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ServletRegistration.java @@ -66,6 +66,7 @@ public class ServletRegistration extends EndpointRegistration<ExtendedServletDTO else { multipartSupport = null; } + needDecode = MatchableRegistration.patternsRequireDecode(servletDTO.patterns); } public ErrorPageDTO getErrorPageDTO() { @@ -116,8 +117,12 @@ public class ServletRegistration extends EndpointRegistration<ExtendedServletDTO return multipartSupport.parseRequest(request); } + @Override + public boolean needDecode() { + return needDecode; + } + private final boolean needDecode; private final ErrorPageDTO errorPageDTO; private final MultipartSupport multipartSupport; - } diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ProxyServlet.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ProxyServlet.java index 08ec8f160..82b21b28b 100644 --- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ProxyServlet.java +++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ProxyServlet.java @@ -62,7 +62,11 @@ public class ProxyServlet extends HttpServlet { checkRuntime(); - String alias = HttpServletRequestWrapperImpl.getDispatchPathInfo(request); + String alias = request.getRequestURI(); + + if (request.getDispatcherType() == DispatcherType.INCLUDE) { + alias = (String)request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI); + } if (alias == null) { alias = Const.SLASH; |