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

ctx.params is an Array with properties, so it cannot be serialized with JSON.stringify. #203

Closed
jesseskinner opened this issue Jan 7, 2015 · 4 comments · Fixed by #205
Closed
Labels

Comments

@jesseskinner
Copy link

The params are not serializable with JSON.stringify(), because they get turned into an empty array and the object properties are lost.

For example, if I have named parameters, like so:

page('/page/:id', function(ctx) {
    console.log(ctx.params, JSON.stringify(ctx.params));
});

then the result in the console will be like this:

[id: "123"] "[]"

Currently I have to do a workaround and copy the parameters over to a normal object before serialization. This works, but having a normal object with named parameters would be cleaner.

For backwards compatibility, since some people are probably assuming ctx.params is an array, maybe there needs to be an additional parameter on ctx that contains an object with only the named parameters, like ctx.namedParams, that is safe to be serialized?

@A
Copy link
Member

A commented Jan 8, 2015

Hm.. I'm thinking about to use object instead array for ctx.params. Need to look does this conditional is working.

@A A added the bug label Jan 8, 2015
@jesseskinner
Copy link
Author

Fantastic, thanks so much for the quick solution!

@A
Copy link
Member

A commented Jan 8, 2015

@jesseskinner Is it work for you? :D If it is, then I'm going to merge the PR into the master.

@jesseskinner
Copy link
Author

@shuvalov-anton Yep, that did the trick. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants