You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2020/08/05 08:01:57 UTC

[wicket] 01/01: WICKEt-6807 Improve the check for the submitting component

This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch WICKET-6807-better-check-for-submitting-component
in repository https://gitbox.apache.org/repos/asf/wicket.git

commit 6cf41bdaf3c2d1b6152a56580545859c0e8357fc
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
AuthorDate: Wed Aug 5 11:00:11 2020 +0300

    WICKEt-6807 Improve the check for the submitting component
    
    First check for the special 'name.x' parameter
    If there is no such then check that there is exactly one 'name' parameter
    Always use only the GET/POST parameters as the form's method
---
 .../org/apache/wicket/markup/html/form/Form.java   | 24 +++++++++++++++++++---
 .../wicket/stateless/StatelessFormUrlTest.java     |  5 +++--
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java
index 1416697..c45756d 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java
@@ -56,6 +56,7 @@ import org.apache.wicket.util.lang.Bytes;
 import org.apache.wicket.util.lang.Generics;
 import org.apache.wicket.util.string.AppendingStringBuffer;
 import org.apache.wicket.util.string.PrependingStringBuffer;
+import org.apache.wicket.util.string.StringValue;
 import org.apache.wicket.util.string.Strings;
 import org.apache.wicket.util.string.interpolator.MapVariableInterpolator;
 import org.apache.wicket.util.value.LongValue;
@@ -447,12 +448,29 @@ public class Form<T> extends WebMarkupContainer
 					if ((form != null) && (form.getRootForm() == Form.this))
 					{
 						String name = submittingComponent.getInputName();
-						IRequestParameters parameters = getRequest().getRequestParameters();
-						if ((!parameters.getParameterValue(name).isNull()) ||
-							!parameters.getParameterValue(name + ".x").isNull())
+						final String method = form.getMethod();
+						IRequestParameters parameters;
+						if (Form.METHOD_POST.equals(method))
+						{
+							parameters = getRequest().getPostParameters();
+						}
+						else
+						{
+							parameters = getRequest().getQueryParameters();
+						}
+						// there is a parameter with the special name then use it
+						if (!parameters.getParameterValue(name + ".x").isNull())
 						{
 							visit.stop(submittingComponent);
 						}
+						else
+						{
+							// otherwise check for a single parameter with that name
+							final List<StringValue> parameterValues = parameters.getParameterValues(name);
+							if (parameterValues != null && parameterValues.size() == 1 && !parameterValues.get(0).isNull()) {
+								visit.stop(submittingComponent);
+							}
+						}
 					}
 				}
 			});
diff --git a/wicket-core/src/test/java/org/apache/wicket/stateless/StatelessFormUrlTest.java b/wicket-core/src/test/java/org/apache/wicket/stateless/StatelessFormUrlTest.java
index d94c094..3e80662 100644
--- a/wicket-core/src/test/java/org/apache/wicket/stateless/StatelessFormUrlTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/stateless/StatelessFormUrlTest.java
@@ -56,7 +56,7 @@ public class StatelessFormUrlTest extends WicketTestCase
 	public void submitLinkInputNameNotEncodedIntoFormAction()
 	{
 		tester.executeUrl("?0-1.IFormSubmitListener-form&text=newValue&submitLink=x");
-		assertEquals("./?-1.-form", tester.getTagById("form1").getAttribute("action"));
+		assertEquals("./?-1.-form&submitLink=x", tester.getTagById("form1").getAttribute("action"));
 	}
 
 	/**
@@ -94,7 +94,8 @@ public class StatelessFormUrlTest extends WicketTestCase
 			Class<?> containerClass)
 		{
 			return new StringResourceStream(
-				"<html><body><form wicket:id=\"form\"><input wicket:id=\"text\"><a wicket:id=\"submitLink\"></a></form></body></html>");
+				"<html><body><form wicket:id=\"form\"><input wicket:id=\"text\"><a "
+				+ "wicket:id=\"submitLink\"></a></form></body></html>");
 		}
 
 	}