Bug 884336 - Remove trailing "/" from URLs when pref to show URLs in titlebar is enabled. r=wesj
authorNicolas Carlo <nickecarlo@gmail.com>
Tue, 02 Jul 2013 15:49:06 -0400
changeset 137233 f568666066f0917e9795da23859ee5f088da922f
parent 137232 09dcdc2b2120e29348af60f3e34a0b7f468bde07
child 137234 c361c2af8910f187eee8714981e2aed99bca9e7c
push id1824
push userryanvm@gmail.com
push dateWed, 03 Jul 2013 18:16:56 +0000
treeherderfx-team@dcbbfcdf7bb4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj
bugs884336
milestone25.0a1
Bug 884336 - Remove trailing "/" from URLs when pref to show URLs in titlebar is enabled. r=wesj
mobile/android/base/util/StringUtils.java
--- a/mobile/android/base/util/StringUtils.java
+++ b/mobile/android/base/util/StringUtils.java
@@ -41,29 +41,46 @@ public class StringUtils {
         if (dot > -1 || colon > -1) {
             return false;
         }
         // Otherwise, text is ambiguous, and we keep its status unchanged
         return wasSearchQuery;
     }
 
     public static String stripScheme(String url) {
-        if (url == null)
+        if (url == null) {
             return url;
+        }
+
+        int start = 0;
+        int end = url.length();
 
         if (url.startsWith("http://")) {
-            return url.substring(7);
+            start = 7;
         }
-        return url;
+
+        if (url.endsWith("/")) {
+            end--;
+        }
+
+        return url.substring(start, end);
     }
 
     public static String stripCommonSubdomains(String host) {
-        if (host == null)
+        if (host == null) {
             return host;
+        }
+
         // In contrast to desktop, we also strip mobile subdomains,
         // since its unlikely users are intentionally typing them
-        if (host.startsWith("www.")) return host.substring(4);
-        else if (host.startsWith("mobile.")) return host.substring(7);
-        else if (host.startsWith("m.")) return host.substring(2);
-        return host;
+        int start = 0;
+
+        if (host.startsWith("www.")) {
+            start = 4;
+        } else if (host.startsWith("mobile.")) {
+            start = 7;
+        } else if (host.startsWith("m.")) {
+            start = 2;
+        }
+
+        return host.substring(start);
     }
-
 }