summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristian Monsen <kristianm@google.com>2010-03-25 18:29:21 +0000
committerKristian Monsen <kristianm@google.com>2010-03-30 15:17:22 +0100
commitfa52d17a04294c245d6b00180bbe03560390c967 (patch)
tree1f5cc4b7f51f68486534906db83cc70471398d3d
parent5149c7b1a265fe8e97fc6f2d372cdc18d7c96d42 (diff)
downloadpackages_apps_Browser-fa52d17a04294c245d6b00180bbe03560390c967.zip
packages_apps_Browser-fa52d17a04294c245d6b00180bbe03560390c967.tar.gz
packages_apps_Browser-fa52d17a04294c245d6b00180bbe03560390c967.tar.bz2
Fix for bug 2538060. Decoding and encoding an URL.
Just encoding [ and ] instead of decoding and encoding again. This is because decoding is not a reversible function so we might not always get back to the same URL. Tested against bug 1634719, which this was a fix for. Change-Id: I041820c15e0a0cf2e6a20bea3801e8b5039d39d5
-rw-r--r--src/com/android/browser/BrowserActivity.java69
1 files changed, 40 insertions, 29 deletions
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java
index 17c66c5..8a61c3e 100644
--- a/src/com/android/browser/BrowserActivity.java
+++ b/src/com/android/browser/BrowserActivity.java
@@ -2797,6 +2797,36 @@ public class BrowserActivity extends Activity
onDownloadStartNoStream(url, userAgent, contentDisposition, mimetype, contentLength);
}
+ // This is to work around the fact that java.net.URI throws Exceptions
+ // instead of just encoding URL's properly
+ // Helper method for onDownloadStartNoStream
+ private static String encodePath(String path) {
+ char[] chars = path.toCharArray();
+
+ boolean needed = false;
+ for (char c : chars) {
+ if (c == '[' || c == ']') {
+ needed = true;
+ break;
+ }
+ }
+ if (needed == false) {
+ return path;
+ }
+
+ StringBuilder sb = new StringBuilder("");
+ for (char c : chars) {
+ if (c == '[' || c == ']') {
+ sb.append('%');
+ sb.append(Integer.toHexString(c));
+ } else {
+ sb.append(c);
+ }
+ }
+
+ return sb.toString();
+ }
+
/**
* Notify the host application a download should be done, even if there
* is a streaming viewer available for thise type.
@@ -2836,35 +2866,16 @@ public class BrowserActivity extends Activity
return;
}
- // java.net.URI is a lot stricter than KURL so we have to undo
- // KURL's percent-encoding and redo the encoding using java.net.URI.
- URI uri = null;
+ // java.net.URI is a lot stricter than KURL so we have to encode some
+ // extra characters. Fix for b 2538060 and b 1634719
+ WebAddress webAddress;
try {
- // Undo the percent-encoding that KURL may have done.
- String newUrl = new String(URLUtil.decode(url.getBytes()));
- // Parse the url into pieces
- WebAddress w = new WebAddress(newUrl);
- String frag = null;
- String query = null;
- String path = w.mPath;
- // Break the path into path, query, and fragment
- if (path.length() > 0) {
- // Strip the fragment
- int idx = path.lastIndexOf('#');
- if (idx != -1) {
- frag = path.substring(idx + 1);
- path = path.substring(0, idx);
- }
- idx = path.lastIndexOf('?');
- if (idx != -1) {
- query = path.substring(idx + 1);
- path = path.substring(0, idx);
- }
- }
- uri = new URI(w.mScheme, w.mAuthInfo, w.mHost, w.mPort, path,
- query, frag);
+ webAddress = new WebAddress(url);
+ webAddress.mPath = encodePath(webAddress.mPath);
} catch (Exception e) {
- Log.e(LOGTAG, "Could not parse url for download: " + url, e);
+ // This only happens for very bad urls, we want to chatch the
+ // exception here
+ Log.e(LOGTAG, "Exception trying to parse url:" + url);
return;
}
@@ -2873,7 +2884,7 @@ public class BrowserActivity extends Activity
String cookies = CookieManager.getInstance().getCookie(url);
ContentValues values = new ContentValues();
- values.put(Downloads.Impl.COLUMN_URI, uri.toString());
+ values.put(Downloads.Impl.COLUMN_URI, webAddress.toString());
values.put(Downloads.Impl.COLUMN_COOKIE_DATA, cookies);
values.put(Downloads.Impl.COLUMN_USER_AGENT, userAgent);
values.put(Downloads.Impl.COLUMN_NOTIFICATION_PACKAGE,
@@ -2884,7 +2895,7 @@ public class BrowserActivity extends Activity
Downloads.Impl.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
values.put(Downloads.Impl.COLUMN_MIME_TYPE, mimetype);
values.put(Downloads.Impl.COLUMN_FILE_NAME_HINT, filename);
- values.put(Downloads.Impl.COLUMN_DESCRIPTION, uri.getHost());
+ values.put(Downloads.Impl.COLUMN_DESCRIPTION, webAddress.mHost);
if (contentLength > 0) {
values.put(Downloads.Impl.COLUMN_TOTAL_BYTES, contentLength);
}