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 373652 d5bc4f182ec309b2d9577b5d7a0414d9d4ed7c0b
parent 373651 9fe977a59fa1656a0a03b8ea1ad6c873520ef1d2
child 373653 564e1f5f214523adc78b1f5ee5a94428c8696343
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1031210
milestone54.0a1
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://");