Java Utililty Methods URL Sanitize

List of utility methods to do URL Sanitize

Description

The list of methods to do URL Sanitize are organized into topic(s).

Method

StringsanitizeCollabNetUrl(String url)
Sanitizes a CollabNet url and make it appropriate to be used by this plugin.
if (url != null && url.endsWith("/")) {
    url = url.substring(0, url.length() - 1);
return url;
StringsanitizeDefaultPort(String url)
Removes the port from a URL if this port is the default one for the URL's scheme.
int afterSchemeIndex = url.indexOf("://");
if (afterSchemeIndex < 0) {
    return url;
String scheme = url.substring(0, afterSchemeIndex);
int fromIndex = scheme.length() + 3;
int ipv6StartIndex = url.indexOf('[', fromIndex);
if (ipv6StartIndex > 0) {
...
StringsanitizeForNextUrl(String url)
Sanitizes the given URL for the parameter Const.ParamsNames#NEXT_URL .
if (url == null) {
    return null;
return url.replace("&", "${amp}").replace("%2B", "${plus}").replace("%23", "${hash}");
StringsanitizeUri(String uri)
sanitize Uri
if (uri.endsWith("/")) {
    uri = uri.substring(0, uri.length() - 1);
return uri.replaceAll("//", "/");
StringsanitizeUri(String uri)
Sanitizes a URI.
if (isSafeUri(uri)) {
    return uri;
} else {
    return "#";
StringsanitizeURL(String url)
sanitize URL
try {
    if (url.substring(0, 7).toLowerCase().equals("http://")) {
        url = url.substring(7);
    } else if (url.substring(0, 8).toLowerCase().equals("https://")) {
        url = url.substring(8);
    } else if (url.charAt(url.length() - 1) == '/') {
        url = url.substring(0, url.length() - 1);
} catch (Exception ex) {
    throw new Exception(ex.getMessage(), ex);
return url;
StringsanitizeUrl(String url)
This method attempts to remove any username and password from the given url String.
if (url == null)
    return null;
return url.replaceAll("(?<=//).*:.*@", "") + "\"]";
StringsanitizeUrl(String url)
sanitize Url
return url.replaceAll("\\\\", "/");
StringsanitizeURL(String url)
Attaches the "/" at end of given url.
if (!url.endsWith("/")) {
    url = url + "/";
return url;
StringsanitizeUrlWithoutProtocol(String url, String protocol)
Sanitizes a given URL to NOT include a protocol prefix.
int i = url.indexOf("://");
if (i >= 0 && url.indexOf('/') - 1 == i) {
    if (!url.substring(0, i).equals(protocol)) {
        throw new IllegalArgumentException(
                "Invalid URL: Uses protocol " + url.substring(0, i) + ", but " + protocol + " required");
    return url.substring(i + 3);
return url;