Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of urlencoded '+' #168

Merged
merged 1 commit into from
Jun 30, 2015
Merged
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
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,15 @@ console.log(color); // prints "red"

Generate a path from a path definition. Both `params` and `queryParams` are optional.

Special characters in `params` and `queryParams` will be urlencoded.

~~~js
var pathDef = "/blog/:cat/:id";
var params = {cat: "meteor", id: "abc"};
var queryParams = {show: "yes", color: "black"};
var params = {cat: "met eor", id: "abc"};
var queryParams = {show: "y+e=s", color: "black"};

var path = FlowRouter.path(pathDef, params, queryParams);
console.log(path); // prints "/blog/meteor/abc?show=yes&color=black"
console.log(path); // prints "/blog/met%20eor/abc?show=y%2Be%3Ds&color=black"
~~~

If there are no params or queryParams, this will simply return the pathDef as it is.
Expand Down
4 changes: 2 additions & 2 deletions client/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Router.prototype.path = function(pathDef, fields, queryParams) {
// remove +?*
key = key.replace(/[\+\*\?]+/g, "");

return fields[key] || "";
return encodeURIComponent(fields[key] || "");
});

var strQueryParams = this._qs.stringify(queryParams || {});
Expand Down Expand Up @@ -326,7 +326,7 @@ Router.prototype.initialize = function() {
};

// initialize
this._page();
this._page({decodeURLComponents: false});
};

Router.prototype._buildTracker = function() {
Expand Down
14 changes: 7 additions & 7 deletions test/client/router.core.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ function (test, next) {

FlowRouter.route(pathDef, {
action: function(params) {
test.equal(params.key, "abc");
test.equal(params.key, "abc +@%");
rendered++;
}
});

FlowRouter.go(pathDef, {key: "abc"});
FlowRouter.go(pathDef, {key: "abc +@%"});

setTimeout(function() {
test.equal(rendered, 1);
Expand Down Expand Up @@ -240,10 +240,10 @@ Tinytest.addAsync('Client - Router - setParams - preserve query strings', functi
}
});

FlowRouter.go(pathDef, {cat: "meteor", id: "200"}, {aa: "20"});
FlowRouter.go(pathDef, {cat: "meteor", id: "200 +%"}, {aa: "20 +%"});
setTimeout(function() {
// return done();
var success = FlowRouter.setParams({id: "700"});
var success = FlowRouter.setParams({id: "700 +%"});
test.isTrue(success);
setTimeout(validate, 50);
}, 50);
Expand All @@ -252,9 +252,9 @@ Tinytest.addAsync('Client - Router - setParams - preserve query strings', functi
test.equal(paramsList.length, 2);
test.equal(queryParamsList.length, 2);

test.equal(_.pick(paramsList[0], "id", "cat"), {cat: "meteor", id: "200"});
test.equal(_.pick(paramsList[1], "id", "cat"), {cat: "meteor", id: "700"});
test.equal(queryParamsList, [{aa: "20"}, {aa: "20"}]);
test.equal(_.pick(paramsList[0], "id", "cat"), {cat: "meteor", id: "200 +%"});
test.equal(_.pick(paramsList[1], "id", "cat"), {cat: "meteor", id: "700 +%"});
test.equal(queryParamsList, [{aa: "20 +%"}, {aa: "20 +%"}]);
done();
}
});
Expand Down