diff options
| author | Ben Murdoch <benm@google.com> | 2009-11-17 13:57:44 +0000 |
|---|---|---|
| committer | Ben Murdoch <benm@google.com> | 2009-11-17 13:57:44 +0000 |
| commit | ca12cfa98fdf995c4cf37f487a050d0d4fb261e0 (patch) | |
| tree | d2f8f8af1ad0eca1a952247849c49e8f64517b30 /src/com/android/browser/AddBookmarkPage.java | |
| parent | 5b75cd02aab6284ec115df8e12228303c2d1ce9d (diff) | |
Do not attempt to parse javascript: bookmarks as URIs, as this often fails.
Bug: http://b/2261225
Change-Id: I3322a2326cdddd290d4c5b95cc87624631d47c00
Diffstat (limited to 'src/com/android/browser/AddBookmarkPage.java')
| -rw-r--r-- | src/com/android/browser/AddBookmarkPage.java | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/src/com/android/browser/AddBookmarkPage.java b/src/com/android/browser/AddBookmarkPage.java index 9ab8473d..a9c72178 100644 --- a/src/com/android/browser/AddBookmarkPage.java +++ b/src/com/android/browser/AddBookmarkPage.java @@ -178,28 +178,33 @@ public class AddBookmarkPage extends Activity { } return false; } - String url = unfilteredUrl; + String url = unfilteredUrl.trim(); try { - URI uriObj = new URI(url); - String scheme = uriObj.getScheme(); - if (!Bookmarks.urlHasAcceptableScheme(url)) { - // If the scheme was non-null, let the user know that we - // can't save their bookmark. If it was null, we'll assume - // they meant http when we parse it in the WebAddress class. - if (scheme != null) { - mAddress.setError(r.getText(R.string.bookmark_cannot_save_url)); - return false; - } - WebAddress address; - try { - address = new WebAddress(unfilteredUrl); - } catch (ParseException e) { - throw new URISyntaxException("", ""); - } - if (address.mHost.length() == 0) { - throw new URISyntaxException("", ""); + // We allow bookmarks with a javascript: scheme, but these will in most cases + // fail URI parsing, so don't try it if that's the kind of bookmark we have. + + if (!url.toLowerCase().startsWith("javascript:")) { + URI uriObj = new URI(url); + String scheme = uriObj.getScheme(); + if (!Bookmarks.urlHasAcceptableScheme(url)) { + // If the scheme was non-null, let the user know that we + // can't save their bookmark. If it was null, we'll assume + // they meant http when we parse it in the WebAddress class. + if (scheme != null) { + mAddress.setError(r.getText(R.string.bookmark_cannot_save_url)); + return false; + } + WebAddress address; + try { + address = new WebAddress(unfilteredUrl); + } catch (ParseException e) { + throw new URISyntaxException("", ""); + } + if (address.mHost.length() == 0) { + throw new URISyntaxException("", ""); + } + url = address.toString(); } - url = address.toString(); } } catch (URISyntaxException e) { mAddress.setError(r.getText(R.string.bookmark_url_not_valid)); |
