PerlDancer / PerlDancer/Dancer2
Deserialization of body broken based on module load order
Nobody has claimed this yet.
- Dominant language
- Perl
- Stars
- 604
- Forks
- 288
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 5
Description
Given the following module Foo:
package Foo;
use Dancer2;
use strict;
use warnings;
set serializer => 'JSON';
# curl -d '{ "key": [ "value" ] }' -H 'Content-Type: application/json' -H 'Expect:' -X POST "http://localhost:5000/"
post '/' => sub {
use Data::Dumper;
print STDERR Dumper['request',request];
print STDERR Dumper['request-params',request->params];
print STDERR Dumper['request-body',request->body];
return param('key');
};
This works:
#!/usr/bin/env perl
use lib '/tmp/dancer-issue';
use Foo;
use Dancer2;
dance;
Output:
$ curl -d '{ "key": [ "value" ] }' -H 'Content-Type: application/json' -H 'Expect:' -X POST "http://localhost:5000/"
["value"]
This does not work:
#!/usr/bin/env perl
use lib '/tmp/dancer-issue';
use Dancer2;
use Foo;
dance;
Output:
$ curl -d '{ "key": [ "value" ] }' -H 'Content-Type: application/json' -H 'Expect:' -X POST "http://localhost:5000/"
$
What's strange is that set serializer in the Foo module does affect the serialization of returned values from routes - so it's not as if it has no effect. It's just broken for deserialization of anything sent via the body.
The module load order in the psgi wrapper is the only thing that changes. I've also tested this under Apache rather than plackup and the repro is the same.
Versions:
$ rpm -q perl-Dancer2 perl-Plack
perl-Dancer2-0.204002-1.noarch
perl-Plack-0.9979-2.el6.rfx.noarch
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.
Research direction
Reproduce the issue with the Foo module and PSGI wrapper, switching only the order of use Dancer2 and use Foo. Compare body deserialization and returned route values in both cases, then trace the serializer setup used by the request body. Done means JSON request bodies deserialize consistently regardless of module load order.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- perl
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100