Bug 417218 - nsStandardURL::SetPath does the wrong thing when the path is '/' and is being set to ''. r+sr=biesi, a=beltzner
authorjwalden@mit.edu
Tue, 26 Feb 2008 14:48:42 -0800
changeset 12288 64c04f0d278624bb52f32671f1a35e6ba99aa34b
parent 12287 0fe6384b447427c3bcfd66b7b6b46885f55a6b74
child 12289 929a4bb77ddbc11c81a0ad5b92d3bd4d12b7f1bf
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbeltzner
bugs417218
milestone1.9b4pre
Bug 417218 - nsStandardURL::SetPath does the wrong thing when the path is '/' and is being set to ''. r+sr=biesi, a=beltzner
netwerk/base/src/nsStandardURL.cpp
netwerk/test/unit/test_standardurl.js
--- a/netwerk/base/src/nsStandardURL.cpp
+++ b/netwerk/base/src/nsStandardURL.cpp
@@ -1476,17 +1476,17 @@ nsStandardURL::SetPath(const nsACString 
 
         spec.Assign(mSpec.get(), mPath.mPos);
         if (path.First() != '/')
             spec.Append('/');
         spec.Append(path);
 
         return SetSpec(spec);
     }
-    else if (mPath.mLen > 1) {
+    else if (mPath.mLen >= 1) {
         mSpec.Cut(mPath.mPos + 1, mPath.mLen - 1);
         // these contain only a '/'
         mPath.mLen = 1;
         mDirectory.mLen = 1;
         mFilepath.mLen = 1;
         // these are no longer defined
         mBasename.mLen = -1;
         mExtension.mLen = -1;
new file mode 100644
--- /dev/null
+++ b/netwerk/test/unit/test_standardurl.js
@@ -0,0 +1,51 @@
+const StandardURL = Components.Constructor("@mozilla.org/network/standard-url;1",
+                                           "nsIStandardURL",
+                                           "init");
+const nsIStandardURL = Components.interfaces.nsIStandardURL;
+
+function symmetricEquality(expect, a, b)
+{
+  do_check_eq(expect, a.equals(b));
+  do_check_eq(expect, b.equals(a));
+}
+
+function test_setEmptyPath()
+{
+  var pairs =
+    [
+     ["http://example.com", "http://example.com/tests/dom/tests"],
+     ["http://example.com:80", "http://example.com/tests/dom/tests"],
+     ["http://example.com:80/", "http://example.com/tests/dom/test"],
+     ["http://example.com/", "http://example.com/tests/dom/tests"],
+     ["http://example.com/a", "http://example.com/tests/dom/tests"],
+     ["http://example.com:80/a", "http://example.com/tests/dom/tests"],
+    ];
+
+  for (var i = 0; i < pairs.length; i++)
+  {
+    var provided = new StandardURL(nsIStandardURL.URLTYPE_AUTHORITY, 80,
+                                   pairs[i][0],
+                                   "UTF-8",
+                                   null);
+
+    var target = new StandardURL(nsIStandardURL.URLTYPE_AUTHORITY, 80,
+                                 pairs[i][1],
+                                 "UTF-8", null);
+
+    provided.QueryInterface(Components.interfaces.nsIURI);
+    target.QueryInterface(Components.interfaces.nsIURI);
+
+    symmetricEquality(false, target, provided);
+
+    provided.path = "";
+    target.path = "";
+
+    do_check_eq(provided.spec, target.spec);
+    symmetricEquality(true, target, provided);
+  }
+}
+
+function run_test()
+{
+  test_setEmptyPath();
+}