From 9a8e044731edf987d8e4b6176447de7bfd7c700d Mon Sep 17 00:00:00 2001 From: "myk%mozilla.org" Date: Sat, 6 May 2006 03:24:15 +0000 Subject: [PATCH] makes the microsummary picker handle invalid and blank URLs bug=336840 r=ben a=ben for branch --- .../bookmarks/content/microsummaryPicker.js | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/browser/components/bookmarks/content/microsummaryPicker.js b/browser/components/bookmarks/content/microsummaryPicker.js index ad46866dde42..aaa6b83885f1 100644 --- a/browser/components/bookmarks/content/microsummaryPicker.js +++ b/browser/components/bookmarks/content/microsummaryPicker.js @@ -67,11 +67,27 @@ var MicrosummaryPicker = { if (this._mode == ADD_BOOKMARK_MODE) return this._ios.newURI(gArg.url, null, null); else if (this._mode == EDIT_BOOKMARK_MODE) { - var uri = BMDS.GetTarget(gResource, gProperties[1], true); - if (uri) { - uri = uri.QueryInterface(Ci.nsIRDFLiteral).Value; - return this._ios.newURI(uri, null, null); + var uriResource = BMDS.GetTarget(gResource, gProperties[1], true); + if (!uriResource) + return null; + + // The URI spec will be the empty string if the user opened the bookmark + // properties dialog via the "New Bookmark" command. + var uriSpec = uriResource.QueryInterface(Ci.nsIRDFLiteral).Value; + if (!uriSpec) + return null; + + // The IO Service will throw an exception if it can't convert the spec + // into an nsIURI object. + var uri; + try { + uri = this._ios.newURI(uriSpec, null, null); } + catch(e) { + return null; + } + + return uri; } return null; @@ -133,13 +149,16 @@ var MicrosummaryPicker = { }, init: function MSP_init() { - this._microsummaries = this._mss.getMicrosummaries(this._pageURI, this._bookmarkID); - this._microsummaries.addObserver(this._observer); - this.rebuild(); + if (this._pageURI) { + this._microsummaries = this._mss.getMicrosummaries(this._pageURI, this._bookmarkID); + this._microsummaries.addObserver(this._observer); + this.rebuild(); + } }, destroy: function MSP_destroy() { - this._microsummaries.removeObserver(this._observer); + if (this._pageURI) + this._microsummaries.removeObserver(this._observer); }, rebuild: function MSP_rebuild() {