Author: bpontarelli
Date: Mon Mar 10 15:35:58 2008
New Revision: 635737

URL: http://svn.apache.org/viewvc?rev=635737&view=rev
Log:
Escaped key prior to OGNL evaluation for label. Test is commented out because I 
couldn't figure out how to get it working.

Modified:
    
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java
    
struts/struts2/trunk/core/src/test/java/org/apache/struts2/components/UIBeanTest.java

Modified: 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java?rev=635737&r1=635736&r2=635737&view=diff
==============================================================================
--- 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java
 (original)
+++ 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java
 Mon Mar 10 15:35:58 2008
@@ -624,7 +624,9 @@
             }
 
             if(this.label == null) {
-                this.label = "%{getText('"+ key +"')}";
+                // Escape the key prior to sending it down
+                String escaped = key.replace("'", "\\'");
+                this.label = "%{getText('" + escaped + "')}";
             }
 
         }

Modified: 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/components/UIBeanTest.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/components/UIBeanTest.java?rev=635737&r1=635736&r2=635737&view=diff
==============================================================================
--- 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/components/UIBeanTest.java
 (original)
+++ 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/components/UIBeanTest.java
 Mon Mar 10 15:35:58 2008
@@ -20,16 +20,15 @@
  */
 package org.apache.struts2.components;
 
+import java.util.Collections;
+import java.util.Map;
+
 import org.apache.struts2.StrutsTestCase;
 import org.springframework.mock.web.MockHttpServletRequest;
 import org.springframework.mock.web.MockHttpServletResponse;
 
 import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.util.ValueStack;
-import com.opensymphony.xwork2.util.ValueStackFactory;
-
-import java.util.Map;
-import java.util.Collections;
 
 /**
  *
@@ -52,7 +51,7 @@
 
         assertEquals("txtFldId", txtFld.getParameters().get("id"));
     }
-    
+
     public void testPopulateComponentHtmlIdWithOgnl() throws Exception {
         ValueStack stack = ActionContext.getContext().getValueStack();
         MockHttpServletRequest req = new MockHttpServletRequest();
@@ -149,4 +148,22 @@
         TextField txtFld = new TextField(stack, req, res);
         assertEquals("12", txtFld.getTheme());
     }
+
+//    I couldn't figure out how to make this test work. Bailing for now.
+//    public void testEscapeLabel() throws Exception {
+//        ValueStack stack = ActionContext.getContext().getValueStack();
+//        MockHttpServletRequest req = new MockHttpServletRequest();
+//        MockHttpServletResponse res = new MockHttpServletResponse();
+//        stack.push(this);
+//
+//        TextField txtFld = new TextField(stack, req, res);
+//        txtFld.setKey("test['foo']");
+//        txtFld.evaluateParams();
+//        assertEquals("test_label", txtFld.getParameters().get("label"));
+//    }
+//
+//    public String getText(String key) {
+//        assertEquals("test[\\'foo\\']", key);
+//        return "test_label";
+//    }
 }


Reply via email to