Commits

Joseph Walton  committed d8bc2ba

Backport the fix for WW-4063; don't evaluate request params.

Backport the changes to UrlHelper from
https://svn.apache.org/viewvc?view=revision&revision=1486633

  • Participants
  • Parent commits 2bc5a29
  • Branches 2_2_6_maintenance

Comments (0)

Files changed (3)

File src/java/com/opensymphony/webwork/views/util/UrlHelper.java

                     if (values[i] != null) {
                         link.append(name);
                         link.append('=');
-                        link.append(translateAndEncode(values[i]));
+                        link.append(encode(values[i]));
                     }
 
                     if (i < (values.length - 1)) {
     }
 
     /**
-     * Translates any script expressions using {@link com.opensymphony.xwork.util.TextParseUtil#translateVariables} and
-     * encodes the URL using {@link java.net.URLEncoder#encode} with the encoding specified in the configuration.
+     * Encodes the URL using {@link java.net.URLEncoder#encode} with the encoding specified in the configuration.
      *
-     * @param input
-     * @return the translated and encoded string
+     * @param input the input to encode
+     * @return the encoded string
      */
-    public static String translateAndEncode(String input) {
-        String translatedInput = translateVariable(input);
+    public static String encode(String input) {
         String encoding = getEncodingFromConfiguration();
 
         try {
-            return URLEncoder.encode(translatedInput, encoding);
+            return URLEncoder.encode(input, encoding);
         } catch (UnsupportedEncodingException e) {
             LOG.warn("Could not encode URL parameter '" + input + "', returning value un-encoded");
-            return translatedInput;
+            return input;
         }
     }
 
-    public static String translateAndDecode(String input) {
-    	String translatedInput = translateVariable(input);
+    /**
+     * Decodes the URL using {@link java.net.URLDecoder#decode(String, String)} with the encoding specified in the configuration.
+     *
+     * @param input the input to decode
+     * @return the encoded string
+     */
+    public static String decode(String input) {
     	String encoding = getEncodingFromConfiguration();
 
         try {
-            return URLDecoder.decode(translatedInput, encoding);
+            return URLDecoder.decode(input, encoding);
         } catch (UnsupportedEncodingException e) {
             LOG.warn("Could not encode URL parameter '" + input + "', returning value un-encoded");
-            return translatedInput;
+            return input;
         }
     }
 
-    private static String translateVariable(String input) {
-    	OgnlValueStack valueStack = ServletActionContext.getContext().getValueStack();
-        String output = TextParseUtil.translateVariables(input, valueStack);
-        return output;
-    }
-
     private static String getEncodingFromConfiguration() {
     	final String encoding;
-        
+
         if (Configuration.isSet(WebWorkConstants.WEBWORK_I18N_ENCODING)) {
             encoding = Configuration.getString(WebWorkConstants.WEBWORK_I18N_ENCODING);
         } else {
                         paramValue = tmpParams[1];
                     }
                     if(paramName != null) {
-                        String translatedParamValue = translateAndDecode(paramValue);
-                        
+                        String translatedParamValue = decode(paramValue);
+
                         if(queryParams.containsKey(paramName)) {
                             // WW-1376 append new param value to existing value(s)
                             Object currentParam = queryParams.get(paramName);

File src/test/com/opensymphony/webwork/views/jsp/URLTagTest.java

         assertEquals("/myapp/company.action", writer.toString());
     }
 
+    public void testEmbeddedParamTagExpressionGetsEvaluatedCorrectly() throws Exception {
+        request.setRequestURI("/public/about");
+        request.setQueryString("section=team&company=acme inc");
+
+        tag.setAction("team");
+        tag.setIncludeParams("all");
+
+        tag.doStartTag();
+
+        Foo foo = new Foo("test");
+        stack.push(foo);
+
+        // include nested param tag
+        ParamTag paramTag = new ParamTag();
+        paramTag.setPageContext(pageContext);
+        paramTag.setName("title");
+        paramTag.setValue("%{title}");
+        paramTag.doStartTag();
+        paramTag.doEndTag();
+
+        tag.doEndTag();
+
+        assertEquals("/team.action?section=team&amp;title=test&amp;company=acme+inc", writer.toString());
+    }
+
     protected void setUp() throws Exception {
         super.setUp();
 
     public class Foo {
         private String title;
 
+        public Foo() {
+        }
+
+        public Foo( String title ) {
+            this.title = title;
+        }
+
         public void setTitle(String title) {
             this.title = title;
         }

File src/test/com/opensymphony/webwork/views/util/UrlHelperTest.java

         assertEquals(values[2], "3");
     }
 
-    public void testTranslateAndEncode() throws Exception {
+    public void testEncode() throws Exception {
     	Object defaultI18nEncoding = Configuration.get(WebWorkConstants.WEBWORK_I18N_ENCODING);
     	try {
     		Configuration.set(WebWorkConstants.WEBWORK_I18N_ENCODING, "UTF-8");
-    		String result = UrlHelper.translateAndEncode("\u65b0\u805e");
+    		String result = UrlHelper.encode("\u65b0\u805e");
     		String expectedResult = "%E6%96%B0%E8%81%9E";
 
     		assertEquals(result, expectedResult);
     	}
     }
 
-    public void testTranslateAndDecode() throws Exception {
+    public void testDecode() throws Exception {
     	Object defaultI18nEncoding = Configuration.get(WebWorkConstants.WEBWORK_I18N_ENCODING);
     	try {
     		Configuration.set(WebWorkConstants.WEBWORK_I18N_ENCODING, "UTF-8");
-    		String result = UrlHelper.translateAndDecode("%E6%96%B0%E8%81%9E");
+    		String result = UrlHelper.decode("%E6%96%B0%E8%81%9E");
     		String expectedResult = "\u65b0\u805e";
 
     		assertEquals(result, expectedResult);