diff --git a/src/Core.js b/src/Core.js index 6fb1b3c9..20d89ee9 100644 --- a/src/Core.js +++ b/src/Core.js @@ -375,7 +375,12 @@ function appendQueryParameters(url, parameters){ q.push(key + "=" + encodeURIComponent(parameters[key])); } } - return url + (useHash ? "#" : (url.indexOf("?") == -1 ? "?" : "&")) + q.join("&") + hash; + if(useHash) { + // Add parameters after existing hash, treating it like a query string + return url + (hash.indexOf("#") == -1 ? "#" : hash + "&") + q.join("&"); + } else { + return url + (url.indexOf("?") == -1 ? "?" : "&") + q.join("&") + hash; + } } diff --git a/src/tests/tests.js b/src/tests/tests.js index d0a940a6..7e8f0883 100644 --- a/src/tests/tests.js +++ b/src/tests/tests.js @@ -112,6 +112,8 @@ function runTests(){ this.url2 = "http://foo.bar:80/a/b/c?d=e#f"; this.url3 = "http://foo.bar:88/a/b/c?d=e#f"; this.url4 = "hTtp://Foo.Bar:88/a/b/c?d=e#f"; + this.url5 = "http://foo.bar:80/a/b/c?d=e#f=g&y=z"; + this.url6 = "http://foo.bar:80/a/b/c?d=e"; }, steps: [{ @@ -147,6 +149,28 @@ function runTests(){ }) === "http://foo.bar:80/a/b/c?d=e&g=h#f"; } + }, { + name: "appendQueryParameters hash without existing hash", + run: function(){ + // Override value for `hash` in config by making new easyXDM.Socket + socket = new easyXDM.Socket({remote:location.href, lazy:true, hash: true }); + + return easyXDM.appendQueryParameters(this.url6, { + g: "h" + }) === + "http://foo.bar:80/a/b/c?d=e#g=h"; + } + }, { + name: "appendQueryParameters hash with existing hash", + run: function(){ + // Override value for `hash` in config by making new easyXDM.Socket + socket = new easyXDM.Socket({remote:location.href, lazy:true, hash: true }); + + return easyXDM.appendQueryParameters(this.url5, { + g: "h" + }) === + "http://foo.bar:80/a/b/c?d=e#f=g&y=z&g=h"; + } }] }, { name: "Check the ACL feature",