Updated Branches: refs/heads/5.3 0301a30f5 -> 6fa4b39eb
FIXED - TAP5-2084: Form should decode its link parameters Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/6fa4b39e Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/6fa4b39e Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/6fa4b39e Branch: refs/heads/5.3 Commit: 6fa4b39ebda5ff63021195e30f27c6bd09fb0a90 Parents: 0301a30 Author: kaosko <[email protected]> Authored: Sat Apr 13 23:15:40 2013 -0700 Committer: kaosko <[email protected]> Committed: Sun Apr 14 07:17:18 2013 +0100 ---------------------------------------------------------------------- .../apache/tapestry5/corelib/components/Form.java | 12 +++- .../tapestry5/integration/app1/FormTests.java | 13 ++++ .../integration/app1/pages/FormLinkParameters.java | 51 +++++++++++++++ .../tapestry5/integration/app1/pages/Index.java | 3 +- .../integration/app1/pages/FormLinkParameters.tml | 16 +++++ 5 files changed, 93 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/6fa4b39e/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java index e2cf36f..5a08e21 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java @@ -44,6 +44,8 @@ import org.slf4j.Logger; import java.io.EOFException; import java.io.IOException; import java.io.ObjectInputStream; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; /** * An HTML form, which will enclose other components to render out the various @@ -394,7 +396,15 @@ public class Form implements ClientElement, FormValidationControl for (String parameterName : link.getParameterNames()) { String value = link.getParameterValue(parameterName); - + // The parameter value is expected to be encoded, + // but the input value shouldn't be encoded. + try + { + value = URLDecoder.decode(value, "UTF-8"); + } catch (UnsupportedEncodingException e) + { + logger.error("Enable to decode parameter value", e); + } writer.element("input", "type", "hidden", "name", parameterName, "value", value); writer.end(); } http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/6fa4b39e/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java index 500d49c..74c0011 100644 --- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java +++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java @@ -1079,4 +1079,17 @@ public class FormTests extends TapestryCoreTestCase assertTextPresent("Selected colors: [Blue, Red]"); } + + @Test + public void checkFormLinkParameters() throws Exception + { + openLinks("FormLinkParameters Demo"); + assertAttribute("//input[@name='myparam']/@value", "!@#$%^&*()_+="); + + clickAndWait("link=SetValue"); + assertTextPresent("Result = '!@#$%^&*()_+='"); + + clickAndWait(SUBMIT); + assertTextPresent("Result = '!@#$%^&*()_+='"); + } } http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/6fa4b39e/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/FormLinkParameters.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/FormLinkParameters.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/FormLinkParameters.java new file mode 100644 index 0000000..96d999c --- /dev/null +++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/FormLinkParameters.java @@ -0,0 +1,51 @@ +// Copyright (c) 2013. The Apache Software Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package org.apache.tapestry5.integration.app1.pages; + +import java.net.URLEncoder; +import org.apache.commons.codec.net.URLCodec; +import org.apache.tapestry5.Link; +import org.apache.tapestry5.annotations.Persist; +import org.apache.tapestry5.annotations.Property; +import org.apache.tapestry5.annotations.RequestParameter; + +public class FormLinkParameters { + + public final static String TEST_PARAM_NAME = "myparam"; + public final static String TEST_PARAM_VALUE = "!@#$%^&*()_+="; + + @Property + private String val; + + @Persist("flash") + @Property + private String result; + + void onDecorateComponentEventLink(Link link) throws Exception + { + // Add parameter to the form submit link and the event link + link.addParameter(TEST_PARAM_NAME, URLEncoder.encode(TEST_PARAM_VALUE, "UTF-8")); + } + + void onMyAction(@RequestParameter(TEST_PARAM_NAME) String value) + { + result = value; // Expecting: value equals TEST_PARAM_VALUE + } + + void onSuccessFromSimpleform(@RequestParameter(TEST_PARAM_NAME) String value) + { + result = value; // Expecting: value equals TEST_PARAM_VALUE + } + +} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/6fa4b39e/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java index 5cacec7..b9c336b 100644 --- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java +++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java @@ -512,8 +512,9 @@ public class Index new Item("FormFragmentExplicitVisibleBoundsDemo", "Form Fragment Explicit Visible Bounds Demo", "Check for form fragment parent visibility can be bounded to"), - new Item("OverrideFieldFocusDemo", "OverrideFieldFocus Demo", "Setting the focus in a form to a specific field") + new Item("OverrideFieldFocusDemo", "OverrideFieldFocus Demo", "Setting the focus in a form to a specific field"), + new Item("FormLinkParameters", "FormLinkParameters Demo", "Form link parameters should be unescaped for a hidden field") ); static http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/6fa4b39e/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/FormLinkParameters.tml ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/FormLinkParameters.tml b/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/FormLinkParameters.tml new file mode 100644 index 0000000..7150b39 --- /dev/null +++ b/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/FormLinkParameters.tml @@ -0,0 +1,16 @@ +<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"> + + <p>Result = '${result}'</p> + + <t:eventLink t:id="eventLink" t:event="MyAction">SetValue</t:eventLink> + + <t:form t:id="simpleform" > + + <t:label for="val" /> + <t:textfield t:id="val" /> + + <input type="submit" value="GO"/> + + </t:form> + +</html>
