From c7d042ef683af91fd4771ceab30b412cd697f5cb Mon Sep 17 00:00:00 2001 From: "jwalden%mit.edu" Date: Tue, 26 Feb 2008 22:48:42 +0000 Subject: [PATCH] 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 | 2 +- netwerk/test/unit/test_standardurl.js | 51 +++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 netwerk/test/unit/test_standardurl.js diff --git a/netwerk/base/src/nsStandardURL.cpp b/netwerk/base/src/nsStandardURL.cpp index a71bba333f4..3ae23b94f81 100644 --- a/netwerk/base/src/nsStandardURL.cpp +++ b/netwerk/base/src/nsStandardURL.cpp @@ -1481,7 +1481,7 @@ nsStandardURL::SetPath(const nsACString &input) 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; diff --git a/netwerk/test/unit/test_standardurl.js b/netwerk/test/unit/test_standardurl.js new file mode 100644 index 00000000000..f20f6f12abe --- /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(); +}