Skip to content

Commit

Permalink
comment addUrlSchemeIfNeeded and why removeLeadingDoubleSlash is used…
Browse files Browse the repository at this point in the history
… there
  • Loading branch information
maxme committed Feb 5, 2015
1 parent 22fc5ea commit c24cf7f
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,21 @@ public static String removeLeadingDoubleSlash(String url, String scheme) {
return url;
}

/**
* Add scheme prefix to an URL. This method must be called on all user entered or server fetched URLs to ensure
* http client will work as expected.
*
* @param url url entered by the user or fetched from a server
* @param isHTTPS true will make the url starts with https;//
* @return transformed url prefixed by its http;// or https;// scheme
*/
public static String addUrlSchemeIfNeeded(String url, boolean isHTTPS) {
if (url == null) {
return null;
}

// Remove leading double slash (eg. //example.com), needed for some wporg instances configured to
// switch between http or https
url = removeLeadingDoubleSlash(url, (isHTTPS ? "https" : "http") + "://");

if (!URLUtil.isValidUrl(url)) {
Expand Down

0 comments on commit c24cf7f

Please sign in to comment.