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 URI encoding for event.trigger #148

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/event.js
Expand Up @@ -22,7 +22,7 @@ module.exports = {
//Change arguments into a real array instead of a fake one
var args = Array.prototype.slice.call(arguments);
//Send all the arguments as JSON
_webview.executeJavascript("webworks.event.trigger('" + name + "', '" + JSON.stringify(args.slice(1)) + "')");
_webview.executeJavascript("webworks.event.trigger('" + name + "', '" + encodeURIComponent(JSON.stringify(args.slice(1))) + "')");
},

add: function (action) {
Expand Down
2 changes: 1 addition & 1 deletion lib/public/event.js
Expand Up @@ -71,7 +71,7 @@ module.exports = {
var parsedArgs;
if (_handlers.hasOwnProperty(name)) {
if (args && args !== "undefined") {
parsedArgs = JSON.parse(args);
parsedArgs = JSON.parse(decodeURIComponent(args));
}
//Call the handlers
_handlers[name].forEach(function (handler) {
Expand Down
6 changes: 3 additions & 3 deletions test/unit/lib/event.js
Expand Up @@ -24,13 +24,13 @@ describe("event", function () {
it("can invoke the webview execute javascript", function () {
spyOn(webview, "executeJavascript");
event.trigger("foo", {"id": 123});
expect(webview.executeJavascript).toHaveBeenCalledWith("webworks.event.trigger('foo', '" + JSON.stringify([{"id": 123}]) + "')");
expect(webview.executeJavascript).toHaveBeenCalledWith("webworks.event.trigger('foo', '" + encodeURIComponent(JSON.stringify([{"id": 123}])) + "')");
});

it("sends multiple arguments passed in across as a JSONified array", function () {
spyOn(webview, "executeJavascript");
event.trigger("foo", {"id": 123}, "Grrrrrrr", "Arrrrg");
expect(webview.executeJavascript).toHaveBeenCalledWith("webworks.event.trigger('foo', '" + JSON.stringify([{"id": 123}, "Grrrrrrr", 'Arrrrg']) + "')");
event.trigger("foo", {"id": 123, "foo": "hello world", list: [1, 2, 3]}, "Grrrrrrr", "Arrrrg");
expect(webview.executeJavascript).toHaveBeenCalledWith("webworks.event.trigger('foo', '" + encodeURIComponent(JSON.stringify([{"id": 123, foo: "hello world", list: [1, 2, 3]}, "Grrrrrrr", 'Arrrrg'])) + "')");
});
});

Expand Down