Skip to content

Unable to format binary payload as command #91

Closed
@z38

Description

@z38
Q A
Bug? yes
New Feature? no
Version master (977edb5)

Actual Behavior

Using CurlCommandFormatter to format a HTTP request with a binary payload throws an exception:

Error: escapeshellarg(): Input string contains NULL bytes
  at vendor/php-http/message/src/Formatter/CurlCommandFormatter.php:43

Expected Behavior

The formatter throws a proper exception or outputs a valid (possibly incomplete) command (see below).

Steps to Reproduce

$requestFactory = Http\Discovery\MessageFactoryDiscovery::find();
$request = $requestFactory->createRequest('POST', 'http://example.com', [], "\0");

$formatter = new Http\Message\Formatter\CurlCommandFormatter();
$formatter->formatRequest($request);

Possible Solutions

In case the formatter should output a command at any times, it should either escape null bytes properly or remove the payload completely. Other tools, such as the network monitor of Firefox, only include url-encoded payloads or multipart parts with Content-Disposition: form-data in the command.

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