Skip to content

Commit ff92c4b

Browse files
authored
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.
1 parent 16ed130 commit ff92c4b

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ dependencies {
223223
compile 'net.lingala.zip4j:zip4j:2.6.4'
224224
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."
225225
compile 'batik:batik-svg-dom:1.6-1'
226+
compile 'com.google.re2j:re2j:1.6'
226227

227228
// ofbiz unit-test compile libs
228229
testCompile 'org.mockito:mockito-core:2.23.0'

framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@
8080

8181
import com.ibm.icu.util.Calendar;
8282

83+
import com.google.re2j.Matcher;
84+
import com.google.re2j.Pattern;
85+
8386
/**
8487
* HttpUtil - Misc HTTP Utility Functions
8588
*/
@@ -1715,7 +1718,7 @@ public static String getRowSubmitPrefix() {
17151718
public static List<String> extractUrls(String input) {
17161719
List<String> result = new ArrayList<String>();
17171720

1718-
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(
1721+
Pattern pattern = Pattern.compile(
17191722
"\\b(((ht|f)tp(s?)\\:\\/\\/|~\\/|\\/)|www.)" +
17201723
"(\\w+:\\w+@)?(([-\\w]+\\.)+(com|org|net|gov" +
17211724
"|mil|biz|info|mobi|name|aero|jobs|museum" +
@@ -1735,7 +1738,7 @@ public static List<String> extractUrls(String input) {
17351738
}
17361739

17371740
if (result.isEmpty()) {
1738-
java.util.regex.Matcher matcher = pattern.matcher(input);
1741+
Matcher matcher = pattern.matcher(input);
17391742
while (matcher.find()) {
17401743
result.add(matcher.group());
17411744
}

0 commit comments

Comments
 (0)