PerlDancer / PerlDancer/Dancer2

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.

Dominant language
Perl
Stars
604
Forks
288
Avg merge
1d 5h
Merged PRs (30d)
5

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

Contributor guide

Open the contributing guide

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.

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.