You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by GitBox <gi...@apache.org> on 2021/03/02 14:14:49 UTC

[GitHub] [tomee] rmannibucau commented on a change in pull request #763: TOMEE-2968: Postgres connection error when a password contains "}"

rmannibucau commented on a change in pull request #763:
URL: https://github.com/apache/tomee/pull/763#discussion_r585598827



##########
File path: container/openejb-core/src/main/java/org/apache/openejb/util/PropertyPlaceHolderHelper.java
##########
@@ -53,33 +55,34 @@ public static void reset() {
     }
 
     public static String simpleValue(final String raw) {
-        if (raw == null) {
-            return null;
-        }
-        if (!raw.contains(PREFIX) || !raw.contains(SUFFIX)) {
-            return String.class.cast(decryptIfNeeded(raw.replace(PREFIX, "").replace(SUFFIX, ""), false));
-        }
-
-        String value = SUBSTITUTOR.replace(raw);
-        if (!value.equals(raw) && value.startsWith("java:")) {
-            value = value.substring(5);
-        }
-        return String.class.cast(decryptIfNeeded(value.replace(PREFIX, "").replace(SUFFIX, ""), false));
+        return String.class.cast(simpleValueAsStringOrCharArray(raw, false));
     }
 
     public static Object simpleValueAsStringOrCharArray(final String raw) {
+        return simpleValueAsStringOrCharArray(raw, true);
+    }
+
+    private static Object simpleValueAsStringOrCharArray(final String raw, boolean acceptCharArray) {
         if (raw == null) {
             return null;
         }
         if (!raw.contains(PREFIX) || !raw.contains(SUFFIX)) {
-            return decryptIfNeeded(raw.replace(PREFIX, "").replace(SUFFIX, ""), true);
+            return decryptIfNeeded(raw, acceptCharArray);
         }
 
         String value = SUBSTITUTOR.replace(raw);
+
         if (!value.equals(raw) && value.startsWith("java:")) {
             value = value.substring(5);
         }
-        return decryptIfNeeded(value.replace(PREFIX, "").replace(SUFFIX, ""), true);
+
+        // no key defined and no escape sequence found -> substitute to key instead
+        if (!(raw.contains(ESCAPE_SEQUENCE) || value.contains(ESCAPE_SEQUENCE))

Review comment:
       I'm not sure you can implement this with "contains" checks (only t"here is none of these chars" test can be reliable) since you need the presence or not of the char + the position between the present ones to have a reliable test otherwise you can fall back in the same issue you originall hit which is to call "replace" where it is not needed.
   
   Test are missing all these weirdo cases but since it is more or less the one you hit I guess it can happen.
   
   A probably trivial fix is to extend PropertiesLookup to handle the fallback replacement (instead of null it returns the key) and just always call the substitutor if there is at least start+end chars. Worse case the substitutor will already do nothing.
   
   Wdyt?




----------------------------------------------------------------
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