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

markt-asf pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 44f55a8164 Follow-on to "Accept the var and value attributes of SSI 
#set in ..."
44f55a8164 is described below

commit 44f55a81646d0174d152ab1246bcee87d5a96f3f
Author: Mark Thomas <[email protected]>
AuthorDate: Mon Oct 19 19:36:03 2026 +0100

    Follow-on to "Accept the var and value attributes of SSI #set in ..."
    
    Align with httpd and process attributes in order
    
    Co-authored by: Claude / Sonnet 5.5
---
 java/org/apache/catalina/ssi/SSISet.java     | 32 +++++------
 test/org/apache/catalina/ssi/TestSSISet.java | 81 +++++++++++++++++++++++-----
 2 files changed, 85 insertions(+), 28 deletions(-)

diff --git a/java/org/apache/catalina/ssi/SSISet.java 
b/java/org/apache/catalina/ssi/SSISet.java
index b21b303520..5d03e747a8 100644
--- a/java/org/apache/catalina/ssi/SSISet.java
+++ b/java/org/apache/catalina/ssi/SSISet.java
@@ -53,37 +53,37 @@ public class SSISet implements SSICommand {
         long lastModified = 0;
         String errorMessage = ssiMediator.getConfigErrMsg();
         String variableName = null;
-        String variableValue = null;
-        // Collect the attributes first so that they can be given in any 
order, as
-        // Apache does
+        boolean variableSeen = false;
+        // As for Apache, a value is assigned to the most recent var attribute 
so
+        // multiple var/value pairs may be used in a single directive and a 
value
+        // must follow the var attribute it applies to
         for (int i = 0; i < paramNames.length; i++) {
             String paramName = paramNames[i];
             String paramValue = paramValues[i];
             if (paramName.equalsIgnoreCase("var")) {
                 variableName = paramValue;
+                variableSeen = true;
             } else if (paramName.equalsIgnoreCase("value")) {
-                variableValue = paramValue;
+                if (variableName == null) {
+                    ssiMediator.log(sm.getString("ssiSet.noVariable"));
+                    writer.write(errorMessage);
+                    throw new SSIStopProcessingException();
+                }
+                String substitutedValue = 
ssiMediator.substituteVariables(paramValue);
+                ssiMediator.setVariableValue(variableName, substitutedValue);
+                lastModified = System.currentTimeMillis();
             } else {
                 ssiMediator.log(sm.getString("ssiCommand.invalidAttribute", 
paramName));
                 writer.write(errorMessage);
                 throw new SSIStopProcessingException();
             }
         }
-        // Both attributes are required, as Apache requires, but they may be
-        // given in any order
-        if (variableName == null) {
-            ssiMediator.log(sm.getString("ssiSet.noVariable"));
+        if (lastModified == 0) {
+            // Nothing was set, so a required attribute was missing
+            ssiMediator.log(sm.getString(variableSeen ? "ssiSet.noValue" : 
"ssiSet.noVariable"));
             writer.write(errorMessage);
             throw new SSIStopProcessingException();
         }
-        if (variableValue == null) {
-            ssiMediator.log(sm.getString("ssiSet.noValue"));
-            writer.write(errorMessage);
-            throw new SSIStopProcessingException();
-        }
-        String substitutedValue = 
ssiMediator.substituteVariables(variableValue);
-        ssiMediator.setVariableValue(variableName, substitutedValue);
-        lastModified = System.currentTimeMillis();
         return lastModified;
     }
 }
diff --git a/test/org/apache/catalina/ssi/TestSSISet.java 
b/test/org/apache/catalina/ssi/TestSSISet.java
index 300c1fc017..a07685bb69 100644
--- a/test/org/apache/catalina/ssi/TestSSISet.java
+++ b/test/org/apache/catalina/ssi/TestSSISet.java
@@ -30,11 +30,11 @@ public class TestSSISet {
 
     @Test
     public void testValueBeforeVar() throws Exception {
-        // The attributes may be given in any order, as Apache does
+        // As for Apache, the var attribute must precede the value attribute
         SSIMediator mediator = newMediator();
         String output = process(mediator, new String[] { "value", "var" }, new 
String[] { "bar", "foo" });
-        Assert.assertEquals("", output);
-        Assert.assertEquals("bar", mediator.getVariableValue("foo"));
+        Assert.assertEquals(mediator.getConfigErrMsg(), output);
+        Assert.assertNull(mediator.getVariableValue("foo"));
     }
 
 
@@ -67,19 +67,76 @@ public class TestSSISet {
 
 
     @Test
-    public void testDuplicateAttributes() throws Exception {
-        // Later occurrences of an attribute win, regardless of order
+    public void testMultiplePairs() throws Exception {
+        // Each value applies to the preceding var, as for Apache
+        SSIMediator mediator = newMediator();
+        String output = process(mediator, new String[] { "var", "value", 
"var", "value" },
+                new String[] { "a", "x", "b", "y" });
+        Assert.assertEquals("", output);
+        Assert.assertEquals("x", mediator.getVariableValue("a"));
+        Assert.assertEquals("y", mediator.getVariableValue("b"));
+    }
+
+
+    @Test
+    public void testRepeatedValue() throws Exception {
+        // Each value is assigned to the current var so the last one wins
+        SSIMediator mediator = newMediator();
+        String output = process(mediator, new String[] { "var", "value", 
"value", "var", "value" },
+                new String[] { "a", "1", "2", "b", "3" });
+        Assert.assertEquals("", output);
+        Assert.assertEquals("2", mediator.getVariableValue("a"));
+        Assert.assertEquals("3", mediator.getVariableValue("b"));
+    }
+
+
+    @Test
+    public void testRepeatedVar() throws Exception {
+        // Only the last var before a value is set
+        SSIMediator mediator = newMediator();
+        String output = process(mediator, new String[] { "var", "var", "value" 
},
+                new String[] { "a", "b", "y" });
+        Assert.assertEquals("", output);
+        Assert.assertNull(mediator.getVariableValue("a"));
+        Assert.assertEquals("y", mediator.getVariableValue("b"));
+    }
+
+
+    @Test
+    public void testTrailingVar() throws Exception {
+        // A trailing var without a value is ignored once something has been 
set, as for Apache
         SSIMediator mediator = newMediator();
-        String output = process(mediator, new String[] { "value", "value", 
"var" },
-                new String[] { "bar1", "bar2", "foo" });
+        String output = process(mediator, new String[] { "var", "value", "var" 
}, new String[] { "a", "x", "b" });
         Assert.assertEquals("", output);
-        Assert.assertEquals("bar2", mediator.getVariableValue("foo"));
+        Assert.assertEquals("x", mediator.getVariableValue("a"));
+        Assert.assertNull(mediator.getVariableValue("b"));
+    }
+
+
+    @Test
+    public void testLeadingValueStopsProcessing() throws Exception {
+        // The leading value is an error so the later var/value pair is never 
applied
+        SSIMediator mediator = newMediator();
+        String output = process(mediator, new String[] { "value", "var", 
"value" }, new String[] { "x", "a", "y" });
+        Assert.assertEquals(mediator.getConfigErrMsg(), output);
+        Assert.assertNull(mediator.getVariableValue("a"));
+    }
 
-        mediator = newMediator();
-        output = process(mediator, new String[] { "var", "value", "value" },
-                new String[] { "foo", "bar1", "bar2" });
+
+    @Test
+    public void testNoAttributes() throws Exception {
+        SSIMediator mediator = newMediator();
+        String output = process(mediator, new String[0], new String[0]);
+        Assert.assertEquals(mediator.getConfigErrMsg(), output);
+    }
+
+
+    @Test
+    public void testEmptyValue() throws Exception {
+        SSIMediator mediator = newMediator();
+        String output = process(mediator, new String[] { "var", "value" }, new 
String[] { "foo", "" });
         Assert.assertEquals("", output);
-        Assert.assertEquals("bar2", mediator.getVariableValue("foo"));
+        Assert.assertEquals("", mediator.getVariableValue("foo"));
     }
 
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to