Skip to content

Commit

Permalink
Improved: In UtilHttp, for regex processing of urls, replace Java reg…
Browse files Browse the repository at this point in the history
…ex with Google RE2J. (#513)

The Main advantage of RE2J is that it guarantees linear time execution.
  • Loading branch information
jacopoc authored Apr 14, 2022
1 parent 16ed130 commit ff92c4b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@

import com.ibm.icu.util.Calendar;

import com.google.re2j.Matcher;
import com.google.re2j.Pattern;

/**
* HttpUtil - Misc HTTP Utility Functions
*/
Expand Down Expand Up @@ -1715,7 +1718,7 @@ public static String getRowSubmitPrefix() {
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" +
Expand All @@ -1735,7 +1738,7 @@ public static List<String> extractUrls(String input) {
}

if (result.isEmpty()) {
java.util.regex.Matcher matcher = pattern.matcher(input);
Matcher matcher = pattern.matcher(input);
while (matcher.find()) {
result.add(matcher.group());
}
Expand Down

0 comments on commit ff92c4b

Please sign in to comment.