Skip to content

Commit 1c2428f

Browse files
committed
Merge branch 'release/5.4' into develop
2 parents f5cf254 + e9f2263 commit 1c2428f

File tree

1 file changed

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

1 file changed

+9
-9
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,25 @@ public static String removeLeadingDoubleSlash(String url, String scheme) {
8686
* http client will work as expected.
8787
*
8888
* @param url url entered by the user or fetched from a server
89-
* @param isHTTPS true will make the url starts with https;//
90-
* @return transformed url prefixed by its http;// or https;// scheme
89+
* @param addHttps true and the url is not starting with http://, it will make the url starts with https://
90+
* @return url prefixed by http:// or https://
9191
*/
92-
public static String addUrlSchemeIfNeeded(String url, boolean isHTTPS) {
92+
public static String addUrlSchemeIfNeeded(String url, boolean addHttps) {
9393
if (url == null) {
9494
return null;
9595
}
9696

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

101-
if (!URLUtil.isValidUrl(url)) {
102-
if (!(url.toLowerCase().startsWith("http://")) && !(url.toLowerCase().startsWith("https://"))) {
103-
url = (isHTTPS ? "https" : "http") + "://" + url;
104-
}
101+
// If the URL is a valid http or https URL, we're good to go
102+
if (URLUtil.isHttpUrl(url) || URLUtil.isHttpsUrl(url)) {
103+
return url;
105104
}
106105

107-
return url;
106+
// Else, remove the old scheme and prefix it by https:// or http://
107+
return (addHttps ? "https" : "http") + "://" + removeScheme(url);
108108
}
109109

110110
/**

0 commit comments

Comments
 (0)