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

rmaucher pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 3881d57e0bf501322164cd6d584610aee55ed66b
Author: opencode <[email protected]>
AuthorDate: Thu Oct 15 11:55:30 2026 +0200

    Quote ObjectName values containing a quote or a newline
    
    The JMX parser rejects unquoted property values containing a double
    quote or a line feed, so such values must be passed through
    ObjectName.quote() before being concatenated into an ObjectName
    string. Util.objectNameValueNeedsQuote() listed only comma, equals,
    colon and the wildcards, so servlet, filter and upgrade protocol
    names containing a double quote bypassed the quoting and the
    subsequent ObjectName construction failed. The call sites catch that
    failure and log a warning, silently leaving the component without a
    JMX registration.
    
    Add the double quote and the line feed to the character check. A
    sweep of the value position of a key property confirms these are the
    only characters, besides the ones already listed, that the parser
    rejects in an unquoted value.
---
 java/org/apache/tomcat/util/modeler/Util.java     |  2 +-
 test/org/apache/tomcat/util/modeler/TestUtil.java | 54 +++++++++++++++++++++++
 2 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/java/org/apache/tomcat/util/modeler/Util.java 
b/java/org/apache/tomcat/util/modeler/Util.java
index 13a313f9de..886ad0bb95 100644
--- a/java/org/apache/tomcat/util/modeler/Util.java
+++ b/java/org/apache/tomcat/util/modeler/Util.java
@@ -35,7 +35,7 @@ public class Util {
     public static boolean objectNameValueNeedsQuote(String input) {
         for (int i = 0; i < input.length(); i++) {
             char ch = input.charAt(i);
-            if (ch == ',' || ch == '=' || ch == ':' || ch == '*' || ch == '?') 
{
+            if (ch == ',' || ch == '=' || ch == ':' || ch == '*' || ch == '?' 
|| ch == '"' || ch == '\n') {
                 return true;
             }
         }
diff --git a/test/org/apache/tomcat/util/modeler/TestUtil.java 
b/test/org/apache/tomcat/util/modeler/TestUtil.java
new file mode 100644
index 0000000000..8a82701031
--- /dev/null
+++ b/test/org/apache/tomcat/util/modeler/TestUtil.java
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+package org.apache.tomcat.util.modeler;
+
+import javax.management.ObjectName;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestUtil {
+
+    @Test
+    public void testObjectNameValueNeedsQuote() {
+        Assert.assertFalse(Util.objectNameValueNeedsQuote("plain"));
+        Assert.assertFalse(Util.objectNameValueNeedsQuote(""));
+
+        Assert.assertTrue(Util.objectNameValueNeedsQuote("a,b"));
+        Assert.assertTrue(Util.objectNameValueNeedsQuote("a=b"));
+        Assert.assertTrue(Util.objectNameValueNeedsQuote("a:b"));
+        Assert.assertTrue(Util.objectNameValueNeedsQuote("a*b"));
+        Assert.assertTrue(Util.objectNameValueNeedsQuote("a?b"));
+        Assert.assertTrue(Util.objectNameValueNeedsQuote("a\"b"));
+        Assert.assertTrue(Util.objectNameValueNeedsQuote("a\nb"));
+    }
+
+    @Test
+    public void testObjectNameValueWithQuoteParsesWhenQuoted() throws 
Exception {
+        String[] values = { "a\"b", "a\nb", "a,\"b\n:c" };
+
+        for (String value : values) {
+            Assert.assertTrue(Util.objectNameValueNeedsQuote(value));
+
+            String onameStr = "tester:type=Tester,name=" + 
ObjectName.quote(value);
+            ObjectName oname = new ObjectName(onameStr);
+
+            // A quoted value is retained with its quoting in the key 
properties
+            Assert.assertEquals(ObjectName.quote(value), 
oname.getKeyPropertyList().get("name"));
+        }
+    }
+}


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

Reply via email to