Commits

Anonymous committed 5d9e6fc

WW-1453 (customOnSubmit_parameters.id() function name cause problem when parameters.id contains forbidden characters)
WW-1442 (webwork tag attribute should take js escaping into account)

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@2973573baa09-0c28-0410-bef9-dab3c582ae83

Comments (0)

Files changed (2)

src/java/com/opensymphony/webwork/components/UIBean.java

     protected String escape(String name) {
         // escape any possible values that can make the ID painful to work with in JavaScript
         if (name != null) {
-            return name.replaceAll("[\\.\\[\\]]", "_");
+            // NOTE:
+            // replace all non a-z, A-Z, 0-9 and '_' to '_'
+            // as javascript spec allows only those characters as it's
+            // attributes. (see WW-1453)
+            return name.replaceAll("[^a-zA-Z0-9_]", "_");
         } else {
             return "";
         }

src/test/com/opensymphony/webwork/components/UIBeanTest.java

  * @version $Date$ $Id$
  */
 public class UIBeanTest extends WebWorkTestCase {
-	public void testPopulateComponentHtmlId1() throws Exception {
+
+    public void testEscape() throws Exception {
+        OgnlValueStack stack = new OgnlValueStack();
+		MockHttpServletRequest req = new MockHttpServletRequest();
+		MockHttpServletResponse res = new MockHttpServletResponse();
+
+        UIBean bean = new UIBean(stack, req, res) {
+            protected String getDefaultTemplate() {
+                return null;
+            }
+        };
+
+        assertEquals(bean.escape("hello[world"), "hello_world");
+        assertEquals(bean.escape("hello.world"), "hello_world");
+        assertEquals(bean.escape("hello]world"), "hello_world");
+        assertEquals(bean.escape("hello!world"), "hello_world");
+        assertEquals(bean.escape("hello!@#$%^&*()world"), "hello__________world");
+    }
+
+    public void testPopulateComponentHtmlId1() throws Exception {
 		OgnlValueStack stack = new OgnlValueStack();
 		MockHttpServletRequest req = new MockHttpServletRequest();
 		MockHttpServletResponse res = new MockHttpServletResponse();
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.