Skip to content

[BUG] Invalid POSTfields parsing in RequestParser #44

Closed
@greevex

Description

@greevex

There some bug in a postfields parsing in file
https://github.com/reactphp/http/blob/master/src/RequestParser.php#L138

Need to replace

parse_str(urldecode($content), $result);

with

parse_str($content, $result);

Example:

// example postfields
$data = [
    'url' => 'http://somedomain/?field1=v1&field2=v2',
    'flag' => 1
];

$string = http_build_query($data);
// encoded to post body as
// url=http%3A%2F%2Fsomedomain%2F%3Ffield1%3Dv1%26field2%3Dv2&flag=1

// So, right way to parse
$result = null;
parse_str($string, $result);
var_dump($result);

array(2) {
  'url' =>
  string(38) "http://somedomain/?field1=v1&field2=v2"
  'flag' =>
  string(1) "1"
}

// and wrong way to parse
$result = null;
parse_str(urldecode($string), $result);
var_dump($result);

array(3) {
  'url' =>
  string(28) "http://somedomain/?field1=v1"
  'field2' =>
  string(2) "v2"
  'flag' =>
  string(1) "1"
}

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