[PATCH] Fix infinite loop on gU

Nicolas Dumazet nicdumz at gmail.com
Sun Dec 26 23:03:31 CST 2010


# HG changeset patch
# User Nicolas Dumazet <nicdumz.commits at gmail.com>
# Date 1293426081 -32400
# Node ID 1eee32dc17c552358df5e8743f6c7239b8e5491f
# Parent  3a1b9bb8c9dcc97e46f762ece3311b3185eadcab
Fix Browser.climbUrlPath when a query parameter contains '//'

When browsing an URL such as
  scheme://path/to/resource/query?param=http%3A//localhost%3A18081/
successive 'gu' commands will stop at
  scheme://path/to/resource/query?param=http%3A//

similarly, gU will loop infinitely, causing firefox to crash.

The /[^\/]+\/?$/ pattern was too simplistic for complex URIs:
rewrite climbUrlPath to parse correctly the resource path.

diff --git a/common/content/browser.js b/common/content/browser.js
--- a/common/content/browser.js
+++ b/common/content/browser.js
@@ -17,8 +17,28 @@
         let url = util.newURI(buffer.URL);
         dactyl.assert(url instanceof Ci.nsIURL);
 
-        while (count-- && url.path != "/")
-            url.path = url.path.replace(/[^\/]+\/?$/, "");
+        if (count < 0) {
+            url.path = "/";
+        } else {
+            let components = url.path.split("/");
+            // find the last path component that is not the query
+            let last = 1;
+            let component;
+            while (last < components.length) {
+                component = components[last];
+                if (component.length == 0 && last == components.length-1) {
+                    // the path ends with a /, strip it
+                    break;
+                }
+                last++;
+                if (component.indexOf("?") >= 0) {
+                    break;
+                }
+            }
+            // note that components[0] is always ""
+            let len = Math.max(last-count, 1);
+            url.path = components.slice(0, len).join("/");
+        }
 
         dactyl.assert(url.spec != buffer.URL);
         dactyl.open(url.spec);


More information about the Mercurial-devel mailing list