Dancer2::Core::Request JSON serialize failed when serialize application/x-www-form-urlencoded

Open
#1,770 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
perl
Domain
api, backend

Research direction

Start with Dancer2::Serializer::JSON.pm around line 47 and reproduce the failure using the generated test_app and the provided curl request. Trace how application/x-www-form-urlencoded requests reach the JSON serializer. Done means the request no longer produces a malformed-JSON 400 error when JSON is configured as the default serializer.

Written by the indexing model from the issue text.

Description

Dancer2 JSON serialize failed to serialize application/x-www-form-urlencoded

What happened: Throw error trying to serialize application/x-www-form-urlencoded
Expected behavior: Not serialize application/x-www-form-urlencoded
Reproduction

$ dancer2 gen-app -d test_app
# edit test_app.pm
package test_app;
use Dancer2;

our $VERSION = '0.1';

+ set serializer => 'JSON'; # set JSON as default serializer

post '/' => sub {
    return "Hello";
};

true;
$ plackup bin/app.psgi

Send a post request with application/x-www-form-urlencoded content

curl -X POST http://localhost:5000 \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'a=b'
# Result
{"title":"Error 400 - Bad Request","status":400,"message":"Failed to deserialize content: malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before \"a=b\") at /home/dai/projects/Dancer2-example/test_app/local/lib/perl5/Dancer2/Serializer/JSON.pm line 47.\n"}

Perl version: 5.42.0
Dancer2 version: 2.0.1

Dominant language
Perl
Stars
607
Forks
289
Avg merge
3d 9h
Merged PRs (30d)
2

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PerlDancer/Dancer2

All issues in PerlDancer/Dancer2

Similar issues

More Perl issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.