Bug 1031210 - Don't assume URL format to prevent crash. r=snorp a=jcristau
authorMichael Kaply <mozilla@kaply.com>
Thu, 23 Feb 2017 11:24:59 -0600
changeset 378772 2a487fe0f3d8a0490bb2d6a3bed75b803d062e06
parent 378771 397bf222b4d46cdac5fb4c2531cdc9d11f0a96f4
child 378773 c38267a9e09e27705a8d92922a08b8a06ce31d15
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp, jcristau
bugs1031210
milestone53.0a2
Bug 1031210 - Don't assume URL format to prevent crash. r=snorp a=jcristau 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://");