Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3614)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/WebsiteSettingsPopup.java

Issue 1011383005: Percent-encode illegal characters in Android page info popup URL (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change unicode representation Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/android/javatests/src/org/chromium/chrome/browser/WebsiteSettingsPopupTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/WebsiteSettingsPopup.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/WebsiteSettingsPopup.java b/chrome/android/java/src/org/chromium/chrome/browser/WebsiteSettingsPopup.java
index 6b6d07a3fa6620310bc2b4716e1851141934c4e4..8f456d0018dc72fab814a2c6b5d4f78cd2b4339d 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/WebsiteSettingsPopup.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/WebsiteSettingsPopup.java
@@ -9,6 +9,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
+import android.net.Uri;
import android.text.Layout;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
@@ -164,6 +165,10 @@ public class WebsiteSettingsPopup implements OnClickListener, OnItemSelectedList
private static final int MAX_TABLET_DIALOG_WIDTH_DP = 400;
+ private static final char FIRST_UNICODE_WHITESPACE = '\u2000';
+ private static final char FINAL_UNICODE_WHITESPACE = '\u200F';
+ private static final char UNICODE_NBSP = '\u00A0';
+
private final Context mContext;
private final Profile mProfile;
private final WebContents mWebContents;
@@ -289,7 +294,8 @@ public class WebsiteSettingsPopup implements OnClickListener, OnItemSelectedList
}
mSecurityLevel = ToolbarModel.getSecurityLevelForWebContents(mWebContents);
- SpannableStringBuilder urlBuilder = new SpannableStringBuilder(mFullUrl);
+ String displayUrl = prepareUrlForDisplay(mFullUrl);
+ SpannableStringBuilder urlBuilder = new SpannableStringBuilder(displayUrl);
OmniboxUrlEmphasizer.emphasizeUrl(urlBuilder, mContext.getResources(), mProfile,
mSecurityLevel, mIsInternalPage, true);
mUrlTitle.setText(urlBuilder);
@@ -300,6 +306,26 @@ public class WebsiteSettingsPopup implements OnClickListener, OnItemSelectedList
}
/**
+ * Percent-encodes suspicious Unicode whitespace characters in a URL so that it can be safely
+ * displayed.
+ */
+ public static String prepareUrlForDisplay(String urlStr) {
+ StringBuilder urlBuilder = new StringBuilder();
+ for (int i = 0; i < urlStr.length(); i++) {
+ char c = urlStr.charAt(i);
+ if ((c >= FIRST_UNICODE_WHITESPACE
+ && c <= FINAL_UNICODE_WHITESPACE)
+ || c == ' '
+ || c == UNICODE_NBSP) {
+ urlBuilder.append(Uri.encode(Character.toString(c)));
+ } else {
+ urlBuilder.append(c);
+ }
+ }
+ return urlBuilder.toString();
+ }
+
+ /**
* Sets the visibility of the lower area of the dialog (containing the permissions and 'Site
* Settings' button).
*
« no previous file with comments | « no previous file | chrome/android/javatests/src/org/chromium/chrome/browser/WebsiteSettingsPopupTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698