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

lukaszlenart pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/struts.git


The following commit(s) were added to refs/heads/main by this push:
     new 402a28d8d WW-3226 test: pin which value wins for each alias/params 
ordering (#1918)
402a28d8d is described below

commit 402a28d8d62be1b83f09acc8a44bb6ae8c8833cb
Author: Lukasz Lenart <[email protected]>
AuthorDate: Sat Sep 12 10:12:33 2026 +0200

    WW-3226 test: pin which value wins for each alias/params ordering (#1918)
    
    The docs now promise that a directly submitted parameter wins when alias
    runs before params, and that the alias overrides it when alias runs after
    params. Cover both orderings so the promise is enforced.
    
    Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
---
 .../struts2/interceptor/AliasInterceptorTest.java  | 31 ++++++++++++++
 core/src/test/resources/struts-alias-ordering.xml  | 47 ++++++++++++++++++++++
 2 files changed, 78 insertions(+)

diff --git 
a/core/src/test/java/org/apache/struts2/interceptor/AliasInterceptorTest.java 
b/core/src/test/java/org/apache/struts2/interceptor/AliasInterceptorTest.java
index 39f2af3ea..35b4811a8 100644
--- 
a/core/src/test/java/org/apache/struts2/interceptor/AliasInterceptorTest.java
+++ 
b/core/src/test/java/org/apache/struts2/interceptor/AliasInterceptorTest.java
@@ -101,6 +101,37 @@ public class AliasInterceptorTest extends XWorkTestCase {
         assertNull("aliasDest must remain unset after a failed conversion", 
action.getAliasDest());
     }
 
+    // WW-3226: there is no 'overwrite' flag; whichever of 'alias' and 
'params' runs last wins when the
+    // request carries both the source name and the alias target. The docs 
promise exactly this.
+    public void testDirectParameterWinsWhenAliasRunsBeforeParams() throws 
Exception {
+        SimpleAction action = 
executeWithBothNamesSubmitted("aliasBeforeParams");
+
+        assertEquals("from-source", action.getAliasSource());
+        assertEquals("direct", action.getAliasDest());
+    }
+
+    public void testAliasOverridesDirectParameterWhenAliasRunsAfterParams() 
throws Exception {
+        SimpleAction action = 
executeWithBothNamesSubmitted("aliasAfterParams");
+
+        assertEquals("from-source", action.getAliasSource());
+        assertEquals("from-source", action.getAliasDest());
+    }
+
+    private SimpleAction executeWithBothNamesSubmitted(String actionName) 
throws Exception {
+        Map<String, Object> params = new HashMap<>();
+        params.put("aliasSource", "from-source");
+        params.put("aliasDest", "direct");
+        ActionContext extraContext = 
ActionContext.of().withParameters(HttpParameters.create(params).build());
+
+        XmlConfigurationProvider provider = new 
StrutsXmlConfigurationProvider("struts-alias-ordering.xml");
+        container.inject(provider);
+        loadConfigurationProviders(provider);
+
+        ActionProxy proxy = actionProxyFactory.createActionProxy("", 
actionName, null, extraContext.getContextMap());
+        proxy.execute();
+        return (SimpleAction) proxy.getAction();
+    }
+
     public void testNameNotAccepted() throws Exception {
         Map<String, Object> params = new HashMap<>();
         params.put("aliasSource", "source here");
diff --git a/core/src/test/resources/struts-alias-ordering.xml 
b/core/src/test/resources/struts-alias-ordering.xml
new file mode 100644
index 000000000..d2c75a63e
--- /dev/null
+++ b/core/src/test/resources/struts-alias-ordering.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+-->
+<!DOCTYPE struts PUBLIC
+        "-//Apache Software Foundation//DTD Struts Configuration 6.0//EN"
+        "https://struts.apache.org/dtds/struts-6.0.dtd";>
+<struts>
+    <include file="xwork-test-default.xml"/>
+    <package name="alias-ordering" extends="xwork-test-default">
+
+        <!-- WW-3226: the order of 'alias' and 'params' decides which value 
wins when both names are submitted -->
+        <action name="aliasBeforeParams" 
class="org.apache.struts2.SimpleAction">
+            <param name="aliases">#{ "aliasSource" : "aliasDest" }</param>
+            <interceptor-ref name="alias"/>
+            <interceptor-ref name="params"/>
+            <result name="success" type="mock"/>
+            <result name="error" type="mock"/>
+        </action>
+
+        <action name="aliasAfterParams" 
class="org.apache.struts2.SimpleAction">
+            <param name="aliases">#{ "aliasSource" : "aliasDest" }</param>
+            <interceptor-ref name="params"/>
+            <interceptor-ref name="alias"/>
+            <result name="success" type="mock"/>
+            <result name="error" type="mock"/>
+        </action>
+
+    </package>
+</struts>

Reply via email to