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 2022/04/14 05:29:12 UTC

[ofbiz-framework] branch release18.12 updated: Improved: In UtilHttp, for regex processing of urls, replace Java regex with Google RE2J. (#513)

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 ff92c4bc9c Improved: In UtilHttp, for regex processing of urls, replace Java regex with Google RE2J. (#513)
ff92c4bc9c is described below

commit ff92c4bc9c180d8cb48949be0d2a7d17d5c14a02
Author: Jacopo Cappellato <ja...@gmail.com>
AuthorDate: Thu Apr 14 07:29:06 2022 +0200

    Improved: In UtilHttp, for regex processing of urls, replace Java regex with Google RE2J. (#513)
    
    The Main advantage of RE2J is that it guarantees linear time execution.
---
 build.gradle                                                       | 1 +
 .../base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java    | 7 +++++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/build.gradle b/build.gradle
index de8cc97917..6a64bdc141 100644
--- a/build.gradle
+++ b/build.gradle
@@ -223,6 +223,7 @@ dependencies {
     compile 'net.lingala.zip4j:zip4j:2.6.4'
     compile 'org.apache.commons:commons-imaging:1.0-alpha2' // Alpha but OK, "Imaging was working and was used by a number of projects in production even before reaching its initial release as an Apache Commons component."
     compile 'batik:batik-svg-dom:1.6-1'
+    compile 'com.google.re2j:re2j:1.6'
 
     // ofbiz unit-test compile libs
     testCompile 'org.mockito:mockito-core:2.23.0'
diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java
index cdcbfb7c13..8f80e389e9 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java
@@ -80,6 +80,9 @@ import org.apache.ofbiz.widget.renderer.VisualTheme;
 
 import com.ibm.icu.util.Calendar;
 
+import com.google.re2j.Matcher;
+import com.google.re2j.Pattern;
+
 /**
  * HttpUtil - Misc HTTP Utility Functions
  */
@@ -1715,7 +1718,7 @@ public final class UtilHttp {
     public static List<String> extractUrls(String input) {
         List<String> result = new ArrayList<String>();
 
-        java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(
+        Pattern pattern = Pattern.compile(
                 "\\b(((ht|f)tp(s?)\\:\\/\\/|~\\/|\\/)|www.)" +
                         "(\\w+:\\w+@)?(([-\\w]+\\.)+(com|org|net|gov" +
                         "|mil|biz|info|mobi|name|aero|jobs|museum" +
@@ -1735,7 +1738,7 @@ public final class UtilHttp {
         }
 
         if (result.isEmpty()) {
-            java.util.regex.Matcher matcher = pattern.matcher(input);
+            Matcher matcher = pattern.matcher(input);
             while (matcher.find()) {
                 result.add(matcher.group());
             }