PerlDancer / PerlDancer/Dancer2
Some JSON requests are modified by Hash::MultiValue
@SysPete is already working on this.
Since Sep 2, 2016.
- Dominant language
- Perl
- Stars
- 604
- Forks
- 288
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 5
Description
I noticed that for some JSON body parameter schemas, arrays are sometimes simply removed when deserialized and stored in request->body_request()
For example, this JSON body parameter:
{
"foo": [ { "bar": 1 } ],
"baz": { "foobar": [ { "blah": 2 } ] }
}
will be parsed into this in a route:
$VAR1 = {
'foo' => {
'bar' => 1
}
'baz' => {
'foobar' => [
{
'blah' => 2
}
]
},
};
Notice that the "foo" field is no longer an array after the deserialization, but the "foobar" field is as expected. I can reproduce this in both 0.202000 and 0.203000.
I tracked it down to the use of Hash::MultiValue->from_mixed(), and with this naive patch it works as expected for me:
--- Dancer2/Core/Request.pm.orig 2016-09-02 11:05:27.042773871 +0200
+++ Dancer2/Core/Request.pm 2016-09-02 11:05:35.714634529 +0200
@@ -213,8 +213,8 @@
# Set body parameters (HMV)
# Not happy with fiddling with Plack::Request internals -- veryrusty Aug 2016.
$self->env->{'plack.request.body'} =
- Hash::MultiValue->from_mixed( ref $data eq 'HASH' ? %$data : () );
+ Hash::MultiValue->new( ref $data eq 'HASH' ? %$data : () );
return $data;
}
I expect my "solution" to break more than it fixes, but I hope that you experts can come up with a better solution.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.