You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2020/02/22 06:31:19 UTC

[ofbiz-framework] branch release18.12 updated: Fixed: replaceFirst sensible to variable pattern (OFBIZ-11396)

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

jleroux pushed a commit to branch release18.12
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/release18.12 by this push:
     new d916b92  Fixed: replaceFirst sensible to variable pattern (OFBIZ-11396)
d916b92 is described below

commit d916b92ec3c01aeecfc1cbe5ebab67419a42f5f9
Author: Jacques Le Roux <ja...@les7arts.com>
AuthorDate: Sat Feb 22 07:21:09 2020 +0100

    Fixed: replaceFirst sensible to variable pattern
    (OFBIZ-11396)
    
    When using variable pattern with replaceFirst you may cross issues if the
    pattern contains specific tokens. For instance on Windows with the path
    "C:\projectsASF\Git\ofbiz-framework/" you have inside the token "\p" which has
    a special meaning.
---
 .../main/java/org/apache/ofbiz/base/util/string/UelFunctions.java  | 7 +++----
 .../src/main/java/org/apache/ofbiz/webtools/WebToolsServices.java  | 3 ++-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java
index a2bcf7c..bf25356 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java
@@ -41,6 +41,7 @@ import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.stream.StreamSource;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.ofbiz.base.location.FlexibleLocation;
 import org.apache.ofbiz.base.util.Debug;
 import org.apache.ofbiz.base.util.FileUtil;
@@ -373,10 +374,8 @@ public class UelFunctions {
     }
 
     public static String replaceFirst(String str1, String str2, String str3) {
-        try {
-            return str1.replaceFirst(str2, str3);
-        } catch (Exception e) {}
-        return null;
+        if (null == str1) return null;
+        return StringUtils.replaceOnce(str1, str2, str3);
     }
 
     public static boolean startsWith(String str1, String str2) {
diff --git a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/WebToolsServices.java b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/WebToolsServices.java
index 9c845e5..473b899 100644
--- a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/WebToolsServices.java
+++ b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/WebToolsServices.java
@@ -48,6 +48,7 @@ import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.ofbiz.base.location.FlexibleLocation;
 import org.apache.ofbiz.base.util.Debug;
 import org.apache.ofbiz.base.util.GeneralException;
@@ -761,7 +762,7 @@ public class WebToolsServices {
                         entityMap.put("title", entity.getTitle());
                         entityMap.put("description", entityDescription);
                         String entityLocation = entity.getLocation();
-                        entityLocation = entityLocation.replaceFirst(System.getProperty("ofbiz.home") + "/", "");
+                        entityLocation = StringUtils.replaceOnce(entityLocation, System.getProperty("ofbiz.home") + "/", "");
                         entityMap.put("location", entityLocation);
                         entityMap.put("javaNameList", javaNameList);
                         entityMap.put("relationsList", relationsList);