From c24cf7fb38d4a9ec34d518f3e4325ef6712b61b7 Mon Sep 17 00:00:00 2001 From: Maxime Biais Date: Thu, 5 Feb 2015 10:20:22 +0100 Subject: [PATCH] comment addUrlSchemeIfNeeded and why removeLeadingDoubleSlash is used there --- .../main/java/org/wordpress/android/util/UrlUtils.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/WordPressUtils/src/main/java/org/wordpress/android/util/UrlUtils.java b/WordPressUtils/src/main/java/org/wordpress/android/util/UrlUtils.java index 9a24929073ab..ec7f0144a757 100644 --- a/WordPressUtils/src/main/java/org/wordpress/android/util/UrlUtils.java +++ b/WordPressUtils/src/main/java/org/wordpress/android/util/UrlUtils.java @@ -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)) {