You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2020/11/13 18:39:28 UTC

[struts] branch WW-5095-cherry-pick created (now 8d3393f)

This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a change to branch WW-5095-cherry-pick
in repository https://gitbox.apache.org/repos/asf/struts.git.


      at 8d3393f  Adds some additional excluded packages

This branch includes the following new commits:

     new a6cd7a0  WW-5095 Sets ActionMapping when preparing a test nv
     new 8bbe194  Avoids recursion in tags
     new 8d3393f  Adds some additional excluded packages

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[struts] 02/03: Avoids recursion in tags

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-5095-cherry-pick
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 8bbe1949e17d58e1b5aef9c71e1279ad12ad7ba7
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Wed Nov 11 07:28:07 2020 +0100

    Avoids recursion in tags
---
 .../org/apache/struts2/components/Component.java    | 11 ++++++++++-
 .../java/org/apache/struts2/components/UIBean.java  | 15 ++++++++-------
 .../apache/struts2/views/jsp/ui/AbstractUITag.java  |  8 ++------
 .../org/apache/struts2/components/UIBeanTest.java   | 21 +++++++++++++++++++++
 .../org/apache/struts2/util/StrutsUtilTest.java     | 15 +++++++++++++++
 .../struts2/views/java/simple/AbstractTest.java     | 14 +++++++-------
 6 files changed, 63 insertions(+), 21 deletions(-)

diff --git a/core/src/main/java/org/apache/struts2/components/Component.java b/core/src/main/java/org/apache/struts2/components/Component.java
index e6c13d3..9d6742f 100644
--- a/core/src/main/java/org/apache/struts2/components/Component.java
+++ b/core/src/main/java/org/apache/struts2/components/Component.java
@@ -300,7 +300,7 @@ public class Component {
      * expression otherwise.
      */
 	protected String completeExpressionIfAltSyntax(String expr) {
-		if (altSyntax()) {
+		if (altSyntax() && !ComponentUtils.containsExpression(expr)) {
 			return "%{" + expr + "}";
 		}
 		return expr;
@@ -383,6 +383,15 @@ public class Component {
     }
 
     /**
+     * Detects if altSyntax is enabled and then checks if expression contains %{...}
+     * @param expr a string to examined
+     * @return true if altSyntax is enabled and expr contains %{...}
+     */
+    protected boolean recursion(String expr) {
+        return ComponentUtils.altSyntax(stack) && ComponentUtils.containsExpression(expr);
+    }
+
+    /**
      * Renders an action URL by consulting the {@link org.apache.struts2.dispatcher.mapper.ActionMapper}.
      * @param action      the action
      * @param namespace   the namespace
diff --git a/core/src/main/java/org/apache/struts2/components/UIBean.java b/core/src/main/java/org/apache/struts2/components/UIBean.java
index f584f97..8c29beb 100644
--- a/core/src/main/java/org/apache/struts2/components/UIBean.java
+++ b/core/src/main/java/org/apache/struts2/components/UIBean.java
@@ -795,8 +795,11 @@ public abstract class UIBean extends Component {
                         addParameter("nameValue", findValue(value, valueClazz));
                     } else if (name != null) {
                         String expr = completeExpressionIfAltSyntax(name);
-
-                        addParameter("nameValue", findValue(expr, valueClazz));
+                        if (recursion(name)) {
+                            addParameter("nameValue", expr);
+                        } else {
+                            addParameter("nameValue", findValue(expr, valueClazz));
+                        }
                     }
                 } else {
                     if (value != null) {
@@ -1030,9 +1033,7 @@ public abstract class UIBean extends Component {
 
     @StrutsTagAttribute(description="HTML id attribute")
     public void setId(String id) {
-        if (id != null) {
-            this.id = findString(id);
-        }
+        this.id = id;
     }
 
     @StrutsTagAttribute(description="The template directory.")
@@ -1250,8 +1251,8 @@ public abstract class UIBean extends Component {
         this.tooltipIconPath = tooltipIconPath;
     }
 
-    public void setDynamicAttributes(Map<String, Object> tagDynamicAttributes) {
-        for (Map.Entry<String, Object> entry : tagDynamicAttributes.entrySet()) {
+    public void setDynamicAttributes(Map<String, String> tagDynamicAttributes) {
+        for (Map.Entry<String, String> entry : tagDynamicAttributes.entrySet()) {
             String key = entry.getKey();
 
             if (!isValidTagAttribute(key)) {
diff --git a/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITag.java b/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITag.java
index 3e4b8db..677892e 100644
--- a/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITag.java
+++ b/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITag.java
@@ -78,7 +78,7 @@ public abstract class AbstractUITag extends ComponentTagSupport implements Dynam
     protected String tooltipIconPath;
 
     // dynamic attributes.
-    protected Map<String, Object> dynamicAttributes = new HashMap<>();
+    protected Map<String, String> dynamicAttributes = new HashMap<>();
 
     protected void populateParams() {
         super.populateParams();
@@ -302,11 +302,7 @@ public abstract class AbstractUITag extends ComponentTagSupport implements Dynam
     }
 
     public void setDynamicAttribute(String uri, String localName, Object value) throws JspException {
-        if (ComponentUtils.altSyntax(getStack()) && ComponentUtils.isExpression(value.toString())) {
-            dynamicAttributes.put(localName, String.valueOf(ObjectUtils.defaultIfNull(findValue(value.toString()), value)));
-        } else {
-            dynamicAttributes.put(localName, value);
-        }
+        dynamicAttributes.put(localName, String.valueOf(value));
     }
 
 }
diff --git a/core/src/test/java/org/apache/struts2/components/UIBeanTest.java b/core/src/test/java/org/apache/struts2/components/UIBeanTest.java
index 3e8547e..387d6b5 100644
--- a/core/src/test/java/org/apache/struts2/components/UIBeanTest.java
+++ b/core/src/test/java/org/apache/struts2/components/UIBeanTest.java
@@ -281,6 +281,27 @@ public class UIBeanTest extends StrutsInternalTestCase {
         assertEquals(value, txtFld.getParameters().get("nameValue"));
     }
 
+    public void testValueParameterRecursion() {
+        ValueStack stack = ActionContext.getContext().getValueStack();
+        MockHttpServletRequest req = new MockHttpServletRequest();
+        MockHttpServletResponse res = new MockHttpServletResponse();
+
+        stack.push(new Object() {
+            public String getMyValue() {
+                return "%{myBad}";
+            }
+            public String getMyBad() {
+                throw new IllegalStateException("Recursion detected!");
+            }
+        });
+
+        TextField txtFld = new TextField(stack, req, res);
+        txtFld.setName("%{myValue}");
+        txtFld.evaluateParams();
+
+        assertEquals("%{myBad}", txtFld.getParameters().get("nameValue"));
+    }
+
     public void testSetClass() {
         String cssClass = "insertCssClassHere";
         ValueStack stack = ActionContext.getContext().getValueStack();
diff --git a/core/src/test/java/org/apache/struts2/util/StrutsUtilTest.java b/core/src/test/java/org/apache/struts2/util/StrutsUtilTest.java
index 28c4b34..02be0f2 100644
--- a/core/src/test/java/org/apache/struts2/util/StrutsUtilTest.java
+++ b/core/src/test/java/org/apache/struts2/util/StrutsUtilTest.java
@@ -189,6 +189,21 @@ public class StrutsUtilTest extends StrutsInternalTestCase {
         assertEquals(obj1, "try: bar");
     }
 
+    public void testTranslateVariablesRecursion() throws Exception {
+        stack.push(new Object() {
+            public String getFoo() {
+                return "%{bar}";
+            }
+            public String getBar() {
+                return "bar";
+            }
+        });
+        String obj1 = strutsUtil.translateVariables("try: %{foo}");
+
+        assertNotNull(obj1);
+        assertEquals("try: %{bar}", obj1);
+    }
+
     // === Junit Hook
 
     protected void setUp() throws Exception {
diff --git a/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/AbstractTest.java b/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/AbstractTest.java
index 00f17fc..f35c03e 100644
--- a/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/AbstractTest.java
+++ b/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/AbstractTest.java
@@ -21,7 +21,6 @@
 
 package org.apache.struts2.views.java.simple;
 
-import com.opensymphony.xwork2.Action;
 import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
 import com.opensymphony.xwork2.inject.Container;
@@ -48,14 +47,15 @@ import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.replay;
 
 public abstract class AbstractTest extends TestCase {
-    private Map<String, String> scriptingAttrs = new HashMap<>();
-    private Map<String, String> commonAttrs = new HashMap<>();
-    private Map<String, Object> dynamicAttrs = new HashMap<>();
+
+    private final Map<String, String> scriptingAttrs = new HashMap<>();
+    private final Map<String, String> commonAttrs = new HashMap<>();
+    private final Map<String, String> dynamicAttrs = new HashMap<>();
 
     protected SimpleTheme theme;
 
     protected StringWriter writer;
-    protected Map map;
+    protected Map<String, Object> map;
 
     protected Template template;
     protected Map<String, Object> stackContext;
@@ -101,7 +101,7 @@ public abstract class AbstractTest extends TestCase {
         stackContext = new HashMap<>();
 
         context = new TemplateRenderingContext(template, writer, stack, map, null);
-        stackContext.put(Component.COMPONENT_STACK, new Stack());
+        stackContext.put(Component.COMPONENT_STACK, new Stack<>());
         ActionContext actionContext = ActionContext.of(stackContext).bind();
 
         request = createNiceMock(HttpServletRequest.class);
@@ -183,7 +183,7 @@ public abstract class AbstractTest extends TestCase {
     }
 
     protected void assertDynamicAttrs(String str) {
-        for (Map.Entry<String, Object> entry : dynamicAttrs.entrySet()) {
+        for (Map.Entry<String, String> entry : dynamicAttrs.entrySet()) {
             String substr = entry.getKey() + "=\"" + entry.getValue() + "\"";
             assertTrue("String [" + substr + "] was not found in [" + str + "]", str.contains(substr));
         }


[struts] 03/03: Adds some additional excluded packages

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-5095-cherry-pick
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 8d3393f09a06ff4a2b6827b6544524d1d6af3c7c
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Fri Nov 13 19:37:02 2020 +0100

    Adds some additional excluded packages
---
 core/src/main/resources/struts-default.xml | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/core/src/main/resources/struts-default.xml b/core/src/main/resources/struts-default.xml
index f73a514..8d30cf4 100644
--- a/core/src/main/resources/struts-default.xml
+++ b/core/src/main/resources/struts-default.xml
@@ -85,7 +85,10 @@
                 com.opensymphony.xwork2.inject.,
                 com.opensymphony.xwork2.ognl.,
                 com.opensymphony.xwork2.security.,
-                com.opensymphony.xwork2.util." />
+                com.opensymphony.xwork2.util.,
+                org.apache.tomcat.,
+                org.apache.catalina.core.,
+                org.wildfly.extension.undertow.deployment." />
 
     <constant name="struts.devMode.excludedPackageNames"
               value="
@@ -223,7 +226,7 @@
 
     <bean type="com.opensymphony.xwork2.config.providers.ValueSubstitutor" class="com.opensymphony.xwork2.config.providers.EnvsValueSubstitutor" scope="singleton"/>
 
-    <package name="struts-default" abstract="true" strict-method-invocation="true">
+    <package name="struts-default" abstract="true">
         <result-types>
             <result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>
             <result-type name="dispatcher" class="org.apache.struts2.result.ServletDispatcherResult" default="true"/>


[struts] 01/03: WW-5095 Sets ActionMapping when preparing a test nv

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-5095-cherry-pick
in repository https://gitbox.apache.org/repos/asf/struts.git

commit a6cd7a0c2553aa8f6d21cd720638dadef2379905
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Wed Nov 11 07:27:40 2020 +0100

    WW-5095 Sets ActionMapping when preparing a test nv
---
 .../junit/src/main/java/org/apache/struts2/StrutsJUnit4TestCase.java    | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/plugins/junit/src/main/java/org/apache/struts2/StrutsJUnit4TestCase.java b/plugins/junit/src/main/java/org/apache/struts2/StrutsJUnit4TestCase.java
index 634cc0a..25fade2 100644
--- a/plugins/junit/src/main/java/org/apache/struts2/StrutsJUnit4TestCase.java
+++ b/plugins/junit/src/main/java/org/apache/struts2/StrutsJUnit4TestCase.java
@@ -131,6 +131,8 @@ public abstract class StrutsJUnit4TestCase<T> extends XWorkJUnit4TestCase {
         ServletActionContext.setRequest(request);
         ServletActionContext.setResponse(response);
 
+        ServletActionContext.getContext().put(ServletActionContext.ACTION_MAPPING, mapping);
+
         return proxy;
     }