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 f648b288d WW-3655 test(freemarker): guard against resolving the result 
location from the request URI (#2037)
f648b288d is described below

commit f648b288d868e9287ae418988eca42553612eb0b
Author: Lukasz Lenart <[email protected]>
AuthorDate: Fri Oct 16 15:43:39 2026 +0200

    WW-3655 test(freemarker): guard against resolving the result location from 
the request URI (#2037)
    
    The behaviour was changed by WW-4169 (2.3.17): a relative location is
    resolved against the action namespace. The test fails when the old
    request-URI based resolution is restored.
    
    Co-authored-by: Claude Opus 5.5 <[email protected]>
---
 .../views/freemarker/FreeMarkerResultTest.java     | 41 ++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git 
a/core/src/test/java/org/apache/struts2/views/freemarker/FreeMarkerResultTest.java
 
b/core/src/test/java/org/apache/struts2/views/freemarker/FreeMarkerResultTest.java
index f8a4bc4da..e4b42e076 100644
--- 
a/core/src/test/java/org/apache/struts2/views/freemarker/FreeMarkerResultTest.java
+++ 
b/core/src/test/java/org/apache/struts2/views/freemarker/FreeMarkerResultTest.java
@@ -28,9 +28,14 @@ import 
org.apache.struts2.views.jsp.StrutsMockHttpServletResponse;
 import org.apache.struts2.views.jsp.StrutsMockServletContext;
 import org.springframework.mock.web.MockHttpServletRequest;
 
+import freemarker.cache.StringTemplateLoader;
+import freemarker.template.Configuration;
+
 import java.io.File;
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * Test case for FreeMarkerResult.
@@ -113,6 +118,42 @@ public class FreeMarkerResultTest extends 
StrutsInternalTestCase {
         assertEquals("text/xml", response.getContentType());
     }
 
+    public void testEmptyLocationDoesNotLoadRequestUriAsTemplate() throws 
Exception {
+        request.setRequestURI("/com/acme/actions/Action.class/");
+        request.setServletPath("/com/acme/actions/Action.class/");
+
+        List<String> requestedTemplates = new ArrayList<>();
+        StringTemplateLoader loader = new StringTemplateLoader() {
+            @Override
+            public Object findTemplateSource(String name) {
+                requestedTemplates.add(name);
+                return super.findTemplateSource(name);
+            }
+        };
+        loader.putTemplate("com/acme/actions/Action.class/", 
"CLASS-FILE-BYTES");
+        Configuration recordingConfiguration = new 
Configuration(Configuration.VERSION_2_3_34);
+        recordingConfiguration.setLocalizedLookup(false);
+        recordingConfiguration.setTemplateLoader(loader);
+
+        FreemarkerResult result = new FreemarkerResult() {
+            @Override
+            protected Configuration getConfiguration() {
+                return recordingConfiguration;
+            }
+        };
+        result.setLocation("");
+        result.setFreemarkerManager(mgr);
+
+        try {
+            result.execute(invocation);
+        } catch (Exception expected) {
+            // a missing template is acceptable, serving the request URI is not
+        }
+
+        assertFalse(stringWriter.toString().contains("CLASS-FILE-BYTES"));
+        assertTrue(requestedTemplates.toString(), 
requestedTemplates.stream().noneMatch(name -> name.contains("Action.class")));
+    }
+
     protected void setUp() throws Exception {
         super.setUp();
         mgr = new FreemarkerManager();

Reply via email to