Skip to content

Commit

Permalink
Regex improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
essiembre committed Aug 14, 2023
1 parent 8a8b50c commit f61402a
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/main/java/com/norconex/commons/lang/url/HttpURL.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.Locale;

import org.apache.commons.lang3.CharUtils;
import org.apache.commons.lang3.RegExUtils;
import org.apache.commons.lang3.StringUtils;

import com.norconex.commons.lang.collection.CollectionUtil;
Expand Down Expand Up @@ -362,7 +361,7 @@ public static String getRoot(String url) {
if (StringUtils.isBlank(url)) {
return null;
}
return RegExUtils.replacePattern(url, "(.*?://[^/?#]+).*", "$1");
return url.replaceFirst("^(.*?://.+?)([/?#]|$)", "$1");
}

/**
Expand Down Expand Up @@ -520,7 +519,7 @@ public static String toAbsolute(String baseURL, String relativeURL) {
}

// Relative to last directory/segment
var base = baseURL.replaceFirst("(.*?)([\\?\\#])(.*)", "$1");
var base = baseURL.replaceFirst("^(.*?)([\\?\\#])(.*)", "$1");
if (StringUtils.countMatches(base, '/') > 2) {
base = base.replaceFirst("(.*/)(.*)", "$1");
}
Expand Down

0 comments on commit f61402a

Please sign in to comment.