Updated Branches: refs/heads/master cb95e2236 -> 1f89691bf
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/1f89691b Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/1f89691b Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/1f89691b Branch: refs/heads/master Commit: 1f89691bf21acd9cde8bccb3e8fc153b76605fab Parents: cb95e22 Author: kaosko <[email protected]> Authored: Sat Apr 13 23:15:40 2013 -0700 Committer: kaosko <[email protected]> Committed: Sat Apr 13 23:15:40 2013 -0700 ---------------------------------------------------------------------- .../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/1f89691b/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 1d526ab..59d2bdd 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 @@ -43,6 +43,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 @@ -363,7 +365,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/1f89691b/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 9b564e3..04d8cfb 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 @@ -1102,4 +1102,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/1f89691b/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/1f89691b/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 3d37f8e..5f575e4 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 @@ -514,8 +514,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/1f89691b/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>
