Skip to content

$c->req->body_data dies internally for JSON request with empty HTTP message body #196

Open
@dboehmer

Description

@dboehmer

I was investigating an issue in our app until I realized there is a bug in Catalyst itself.

How to reproduce:

  • have an app read $c->req->body_data—I tried this with a fresh app created by catalyst.pl by just adding that call to the default action method
  • send invalid JSON like this:
curl -v --json '' http://localhost:3000/

Actual result:

[error] Error Parsing POST 'undef', Error: Can't locate object method "getline" via package "0" (perhaps you forgot to load "0"?) at .../perlbrew/perls/perl-5.38.0-threads-bullseye/lib/site_perl/5.38.0/Catalyst.pm line 4091.

Expected result:

  • either return (); or a catchable exception from parsing the empty string

I think Pull Request #186 solves part of the problem related with repeated calls on $c->req->body_data but with that the code already fails on $fh->seek (see my comment there). Currently the data handler fails for $fh->getline.

Should the data handler always receive a filehandle, possibly an empty one, or does every data handler need to check whether a filehandle is present first?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions