You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by GitBox <gi...@apache.org> on 2020/06/26 20:22:12 UTC

[GitHub] [tomcat] ChristopherSchultz commented on a change in pull request #309: Allow recursive substitution of properties.

ChristopherSchultz commented on a change in pull request #309:
URL: https://github.com/apache/tomcat/pull/309#discussion_r446392364



##########
File path: java/org/apache/tomcat/util/IntrospectionUtils.java
##########
@@ -332,7 +341,15 @@ public static String replaceProperties(String value,
         }
         if (prev < value.length())
             sb.append(value.substring(prev));
-        return sb.toString();
+        String newval = sb.toString();
+        if (newval.indexOf('$') < 0) {
+            return newval;
+        }
+        if (newval.equals(value))
+            return value;
+        if (log.isDebugEnabled())
+            log.debug("IntrospectionUtils.replaceProperties iter on: " + newval);
+        return replaceProperties(newval, staticProp, dynamicProp, classLoader, iterationCount+1);

Review comment:
       Does this need to be recursive? Can we not simply have a loop of replacements?

##########
File path: java/org/apache/tomcat/util/IntrospectionUtils.java
##########
@@ -285,10 +285,19 @@ public static Object getProperty(Object o, String name) {
     public static String replaceProperties(String value,
             Hashtable<Object,Object> staticProp, PropertySource dynamicProp[],
             ClassLoader classLoader) {
+            return replaceProperties(value, staticProp, dynamicProp, classLoader, 0);
+    }
 
+    private static String replaceProperties(String value,
+            Hashtable<Object,Object> staticProp, PropertySource dynamicProp[],
+            ClassLoader classLoader, int iterationCount) {
         if (value.indexOf('$') < 0) {

Review comment:
       We should be looking for `${` and not `$`. Class names often contain `$` because of nested classes, and class names are often used in system properties. Plus, if we are looking for `${` we should look for `${`.
   
   I realize that this is existing code, but we may as well improve it while we're in here.

##########
File path: java/org/apache/tomcat/util/IntrospectionUtils.java
##########
@@ -332,7 +341,15 @@ public static String replaceProperties(String value,
         }
         if (prev < value.length())
             sb.append(value.substring(prev));
-        return sb.toString();
+        String newval = sb.toString();
+        if (newval.indexOf('$') < 0) {

Review comment:
       Same, here: look for `${`, not `$`.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org