Bug 1031210 - Don't assume URL format to prevent crash. r=snorp
authorMichael Kaply <mozilla@kaply.com>
Thu, 23 Feb 2017 11:24:59 -0600
changeset 344625 d5bc4f182ec309b2d9577b5d7a0414d9d4ed7c0b
parent 344624 9fe977a59fa1656a0a03b8ea1ad6c873520ef1d2
child 344626 564e1f5f214523adc78b1f5ee5a94428c8696343
push id31414
push usercbook@mozilla.com
push dateFri, 24 Feb 2017 10:47:41 +0000
treeherdermozilla-central@be661bae6cb9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1031210
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1031210 - Don't assume URL format to prevent crash. r=snorp MozReview-Commit-ID: 23qE4mI5tBU
mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/StringUtils.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/StringUtils.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/StringUtils.java
@@ -97,30 +97,29 @@ public class StringUtils {
         return stripScheme(url, UrlFlags.NONE);
     }
 
     public static String stripScheme(String url, int flags) {
         if (url == null) {
             return url;
         }
 
-        int start = 0;
-        int end = url.length();
+        String newURL = url;
 
-        if (url.startsWith("http://")) {
-            start = 7;
-        } else if (url.startsWith("https://") && flags == UrlFlags.STRIP_HTTPS) {
-            start = 8;
+        if (newURL.startsWith("http://")) {
+            newURL = newURL.replace("http://", "");
+        } else if (newURL.startsWith("https://") && flags == UrlFlags.STRIP_HTTPS) {
+            newURL = newURL.replace("https://", "");
         }
 
-        if (url.endsWith("/")) {
-            end--;
+        if (newURL.endsWith("/")) {
+            newURL = newURL.substring(0, newURL.length()-1);
         }
 
-        return url.substring(start, end);
+        return newURL;
     }
 
     public static boolean isHttpOrHttps(String url) {
         if (TextUtils.isEmpty(url)) {
             return false;
         }
 
         return url.startsWith("http://") || url.startsWith("https://");