Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2020-06-29 18:40:59 +0000
committerThomas Watson2020-06-29 19:11:33 +0000
commitb4a5f29b1a77de9e1fd21936ce073af27ccfb157 (patch)
tree995c32eba5f388d1e7f9111246631fe5c29780e5 /bundles
parentb0a95ae20be20cdf104fd35dd65f94c5d6369ec3 (diff)
downloadrt.equinox.bundles-b4a5f29b1a77de9e1fd21936ce073af27ccfb157.tar.gz
rt.equinox.bundles-b4a5f29b1a77de9e1fd21936ce073af27ccfb157.tar.xz
rt.equinox.bundles-b4a5f29b1a77de9e1fd21936ce073af27ccfb157.zip
Bug 564747 - Fix empty query params to use the empty stringI20200629-1800
Fix the query string parameter map parsing treat empty params to be set to the empty string. Change-Id: Ie86757fa0a440bda42f32e5830a1de34964f6fe7 Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/testbase/AllTests.java6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/Bug564747_Test.java76
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/DispatchTargets.java4
3 files changed, 82 insertions, 4 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 809779fa0..cb4c7897d 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2016, 2019 IBM Corporation and others.
+ * Copyright (c) 2016, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -17,6 +17,7 @@ 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_2_Test;
import org.eclipse.equinox.http.servlet.tests.Bug562843_Test;
+import org.eclipse.equinox.http.servlet.tests.Bug564747_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;
@@ -100,7 +101,8 @@ import org.junit.runners.Suite.SuiteClasses;
ContextHelperCustomizerTests.class,
Bug500783_Test.class,
Bug562843_Test.class,
- Bug562843_2_Test.class
+ Bug562843_2_Test.class,
+ Bug564747_Test.class
})
public class AllTests {
// see @SuiteClasses
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/Bug564747_Test.java b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/Bug564747_Test.java
new file mode 100644
index 000000000..6c415af55
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/Bug564747_Test.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2020 IBM Corporation and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Arrays;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+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 Bug564747_Test extends BaseTest {
+
+ @Test
+ public void test() throws Exception {
+ Servlet servlet = new HttpServlet() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void doGet(
+ HttpServletRequest req, HttpServletResponse resp)
+ throws IOException {
+
+ PrintWriter writer = resp.getWriter();
+ writer.write(req.getQueryString());
+ writer.write("|");
+ writer.write(String.valueOf(req.getParameter("p")));
+ writer.write("|");
+ writer.write(Arrays.toString(req.getParameterValues("p")));
+ writer.write("|");
+ writer.write(String.valueOf(req.getParameter("q")));
+ writer.write("|");
+ writer.write(Arrays.toString(req.getParameterValues("q")));
+ writer.write("|");
+ writer.write(String.valueOf(req.getParameter("r")));
+ writer.write("|");
+ writer.write(Arrays.toString(req.getParameterValues("r")));
+ writer.write("|");
+ writer.write(String.valueOf(req.getParameter("s")));
+ writer.write("|");
+ writer.write(Arrays.toString(req.getParameterValues("s")));
+ }
+ };
+
+ Dictionary<String, Object> props = new Hashtable<>();
+ props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "S13");
+ props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/Servlet13/*");
+ registrations.add(getBundleContext().registerService(Servlet.class, servlet, props));
+
+ String result = requestAdvisor.request("Servlet13/a?p=&q=&q=2&r=3");
+
+ Assert.assertEquals("Wrong result: " + result, "p=&q=&q=2&r=3||[]||[, 2]|3|[3]|null|null", result);
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/DispatchTargets.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/DispatchTargets.java
index 14a1beb53..d29238420 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/DispatchTargets.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/DispatchTargets.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2014, 2016 Raymond Augé and others.
+ * Copyright (c) 2014, 2020 Raymond Augé and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -221,7 +221,7 @@ public class DispatchTargets {
if (values == null) {
values = new String[0];
}
- String value = ((index > 0) && (parameter.length() > index + 1)) ? URLDecoder.decode(parameter.substring(index + 1), Const.UTF8) : null;
+ String value = ((index > 0) && (parameter.length() > index + 1)) ? URLDecoder.decode(parameter.substring(index + 1), Const.UTF8) : ""; //$NON-NLS-1$
values = Params.append(values, value);
parameterMap.put(name, values);
}

Back to the top