Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Add support for passing parameters to provider through hash along with existing hash #215

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}


Expand Down
24 changes: 24 additions & 0 deletions src/tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [{
Expand Down Expand Up @@ -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",
Expand Down