Skip to content

Commit d61a71f

Browse files
committed
comment addUrlSchemeIfNeeded and why removeLeadingDoubleSlash is used there
1 parent 29beaed commit d61a71f

File tree

1 file changed

+10
-0
lines changed
  • WordPressUtils/src/main/java/org/wordpress/android/util

1 file changed

+10
-0
lines changed

WordPressUtils/src/main/java/org/wordpress/android/util/UrlUtils.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,21 @@ public static String removeLeadingDoubleSlash(String url, String scheme) {
7272
return url;
7373
}
7474

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

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

8292
if (!URLUtil.isValidUrl(url)) {

0 commit comments

Comments
 (0)