From 9725a77611e777b09858102dcd4188e8b9982fe3 Mon Sep 17 00:00:00 2001 From: John Foerch Date: Sun, 29 Jan 2012 23:07:06 -0500 Subject: [PATCH] browser_object_up_url: support trimming #ref (fragment) compute_url_up_path: removed compute_up_url: new function resolves issue275 --- modules/element.js | 3 +-- modules/utils.js | 21 +++++++++------------ 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/modules/element.js b/modules/element.js index 2c963bc..f018261 100644 --- a/modules/element.js +++ b/modules/element.js @@ -248,8 +248,7 @@ define_browser_object_class("scrape-url", define_browser_object_class("up-url", "Browser object which returns the url one level above the current one.", function (I, prompt) { - var up = compute_url_up_path(I.buffer.current_uri.spec); - return I.buffer.current_uri.resolve(up); + return compute_up_url(I.buffer.current_uri); }); define_browser_object_class("focused-element", diff --git a/modules/utils.js b/modules/utils.js index f77eb57..89fde07 100644 --- a/modules/utils.js +++ b/modules/utils.js @@ -680,18 +680,15 @@ function build_url_regexp () { } -function compute_url_up_path (url) { - var new_url = Cc["@mozilla.org/network/standard-url;1"] - .createInstance (Ci.nsIURL); - new_url.spec = url; - var up; - if (new_url.param != "" || new_url.query != "") - up = new_url.filePath; - else if (new_url.fileName != "") - up = "."; - else - up = ".."; - return up; +function compute_up_url (uri) { + uri = uri.clone().QueryInterface(Ci.nsIURL); + for each (var p in ["ref", "query", "param", "fileName"]) { + if (uri[p] != "") { + uri[p] = ""; + return uri.spec; + } + } + return uri.resolve(".."); } -- 2.11.4.GIT