You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by cb...@apache.org on 2026/06/18 11:32:43 UTC

(velocity-tools) branch master updated: VELTOOLS-214 - fix ignored createSession="false" in tools.xml

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

asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/velocity-tools.git


The following commit(s) were added to refs/heads/master by this push:
     new 634d0ef3 VELTOOLS-214 - fix ignored createSession="false" in tools.xml
634d0ef3 is described below

commit 634d0ef31d3542fb2ff4a532e38e7498e84972a4
Author: Claude Brisson <cl...@renegat.net>
AuthorDate: Thu Jun 18 13:30:38 2026 +0200

    VELTOOLS-214 - fix ignored createSession="false" in tools.xml
---
 src/changes/changes.xml                            |  4 ++++
 .../org/apache/velocity/tools/ToolboxFactory.java  | 15 ++++++++++++
 .../velocity/tools/view/ViewToolManager.java       | 11 +++++----
 .../velocity/tools/view/ViewToolManagerTest.java   | 28 ++++++++++++++++++++++
 4 files changed, 54 insertions(+), 4 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 67736a9a..07525e52 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -46,7 +46,11 @@
           strict mode throws and non-strict mode renders the reference literally (a warning is still logged).
       </action>
     </release>
+
     <release version="3.2" date="TBD">
+      <action type="fix" dev="cbrisson" issue="VELTOOLS-214">
+          tools's XML session scope createSesison="false" was ignored
+      </action>
       <action type="fix" dev="cbrisson" issue="VELTOOLS-143">
           LinkTool no longer drops parameters on opaque (e.g. mailto:) URIs; param() values are merged
           into the scheme-specific part, including any query already present in the URI.
diff --git a/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolboxFactory.java b/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolboxFactory.java
index 52a875ec..27e7b54b 100644
--- a/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolboxFactory.java
+++ b/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ToolboxFactory.java
@@ -205,6 +205,21 @@ public class ToolboxFactory
         return globalProperties.get(name);
     }
 
+    /**
+     * Returns the value of a property for the given scope, falling back to the
+     * factory-global properties when that scope does not define it. This lets a
+     * scope-level setting (e.g. createSession on the session toolbox) be honored.
+     * @param scope toolbox scope
+     * @param name property name
+     * @return property value, or null if neither the scope nor the globals define it
+     */
+    public Object getProperty(String scope, String name)
+    {
+        Map<String,Object> props = scopedProperties.get(scope);
+        Object value = (props == null) ? null : props.get(name);
+        return (value != null) ? value : getGlobalProperty(name);
+    }
+
     public Map<String,Object> getData()
     {
         return data;
diff --git a/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ViewToolManager.java b/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ViewToolManager.java
index c6273dca..02221d9e 100644
--- a/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ViewToolManager.java
+++ b/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ViewToolManager.java
@@ -180,12 +180,15 @@ public class ViewToolManager extends ToolManager
      */
     protected void updateGlobalProperties()
     {
-        // check for a createSession setting
-        Boolean create =
-            (Boolean)this.factory.getGlobalProperty(CREATE_SESSION_PROPERTY);
+        // check for a createSession setting; it is honored at the session-toolbox level
+        // (where it naturally belongs and is bundled/documented), falling back to a
+        // factory-global property. The toolbox-attribute form arrives as a String.
+        Object create = this.factory.getProperty(Scope.SESSION, CREATE_SESSION_PROPERTY);
         if (create != null)
         {
-            setCreateSession(create);
+            setCreateSession(create instanceof Boolean
+                             ? (Boolean)create
+                             : Boolean.parseBoolean(create.toString()));
         }
 
         // check for a publishToolboxes setting
diff --git a/velocity-tools-view/src/test/java/org/apache/velocity/tools/view/ViewToolManagerTest.java b/velocity-tools-view/src/test/java/org/apache/velocity/tools/view/ViewToolManagerTest.java
index a6382697..f675bd66 100644
--- a/velocity-tools-view/src/test/java/org/apache/velocity/tools/view/ViewToolManagerTest.java
+++ b/velocity-tools-view/src/test/java/org/apache/velocity/tools/view/ViewToolManagerTest.java
@@ -20,11 +20,16 @@ package org.apache.velocity.tools.view;
 
 import jakarta.servlet.ServletContext;
 
+import org.apache.velocity.tools.Scope;
+import org.apache.velocity.tools.config.FactoryConfiguration;
+import org.apache.velocity.tools.config.ToolboxConfiguration;
 import org.junit.Test;
 
 import static org.easymock.EasyMock.createNiceMock;
 import static org.easymock.EasyMock.replay;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 /**
  * Regression for the auto-configuring constructor: it used to call {@code autoConfigure()}
@@ -40,4 +45,27 @@ public class ViewToolManagerTest
         ViewToolManager manager = new ViewToolManager(app);
         assertNotNull(manager);
     }
+
+    // VELTOOLS-214: createSession="false" set on the session toolbox (as bundled and
+    // documented) must reach the manager, not be silently ignored.
+    @Test
+    public void sessionToolboxCreateSessionFalseIsHonored()
+    {
+        ServletContext app = createNiceMock(ServletContext.class);
+        replay(app);
+
+        ViewToolManager manager = new ViewToolManager(app, false, false);
+        assertTrue("createSession defaults to true", manager.getCreateSession());
+
+        FactoryConfiguration config = new FactoryConfiguration();
+        ToolboxConfiguration session = new ToolboxConfiguration();
+        session.setScope(Scope.SESSION);
+        // the toolbox-attribute form arrives as a String
+        session.setProperty(ViewToolManager.CREATE_SESSION_PROPERTY, "false");
+        config.addToolbox(session);
+        manager.configure(config);
+
+        assertFalse("session-toolbox createSession=\"false\" must be honored",
+                    manager.getCreateSession());
+    }
 }