@@ -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 isHTTPS true will make the url starts with https: //
90+ * @return transformed url prefixed by its http: // or https: // scheme
9191 */
92- public static String addUrlSchemeIfNeeded (String url , boolean isHTTPS ) {
92+ public static String addUrlSchemeIfNeeded (String url , boolean isHttps ) {
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 , (isHttps ? "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 add prefix it by https:// or http://
107+ return (isHttps ? "https" : "http" ) + "://" + removeScheme (url );
108108 }
109109
110110 /**
0 commit comments