Bug 1563039 - Fix erroneous base domain highlighting. r=VladBaicu, a=RyanVM
authorJan Henning <jh+bugzilla@buttercookie.de>
Tue, 09 Jul 2019 11:43:32 +0000
changeset 541361 20015237f3bf35daa3265a18bb8c7a3ac0a2ebd6
parent 541360 0c8aee9afd1cea471b474c80510cfc2aa2f4aed9
child 541362 e7256a4fce27feafcc4c663262ed4f6486517235
push id11584
push userryanvm@gmail.com
push dateMon, 15 Jul 2019 17:35:02 +0000
treeherdermozilla-beta@e5d98eda2ec3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersVladBaicu, RyanVM
bugs1563039
milestone69.0
Bug 1563039 - Fix erroneous base domain highlighting. r=VladBaicu, a=RyanVM Domain highlighting needs to find the *last* instance of the base domain within the domain part of the URL. Otherwise, there's a chance we mistakenly highlight (parts of) a subdomain if it matches the base domain, too. Differential Revision: https://phabricator.services.mozilla.com/D37311
mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/StringUtils.java
--- a/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
+++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
@@ -327,17 +327,23 @@ public class ToolbarDisplayLayout extend
     }
 
     private void updateAndColorTitleFromFullURL(String url, String baseDomain, boolean isPrivate) {
         if (TextUtils.isEmpty(baseDomain)) {
             setTitle(url);
             return;
         }
 
-        int index = url.indexOf(baseDomain);
+        // Check if the URL contains something that looks like a path segment -
+        // we only want to find highlighting targets within the domain segment.
+        int domainEnd = StringUtils.pathStartIndex(url);
+        if (domainEnd == -1) {
+            domainEnd = url.length();
+        }
+        int index = url.lastIndexOf(baseDomain, domainEnd);
         if (index == -1) {
             setTitle(url);
             return;
         }
 
         final SpannableStringBuilder builder = new SpannableStringBuilder(url);
 
         builder.setSpan(isPrivate ? mPrivateUrlColorSpan : mUrlColorSpan, 0, url.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
--- 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
@@ -250,17 +250,17 @@ public class StringUtils {
      *
      * @return a set of decoded names
      */
     public static Set<String> getQueryParameterNames(final Uri uri) {
         return uri.getQueryParameterNames();
     }
 
     /**
-     * @return  the index of the path segment of URLs
+     * @return  The index of the path segment of an URL, or -1 if no path segment was detected.
      */
     public static int pathStartIndex(final String text) {
         if (text.contains("://")) {
             return text.indexOf('/', text.indexOf("://") + 3);
         } else {
             return text.indexOf('/');
         }
     }