guzzle/guzzle — pull request #758 by rjkip (2014-08-06 11:47:55+00:00)
Title: Test ampersand in multipart field value

Using Guzzle 4.1.2, I was POSTing some key/values and files (ie. multipart), and received a Bad Request response stating a date was formatted incorrectly. The original date string was `2013-12-20T09:52:49+0100`, but it is posted as `2013-12-20T09:52:49 0100`. Note that the plus sign was replaced by a space.

On master, this bug no longer occurs, but the issue hasn't been fully addressed. In the PR you'll find a failing test. My question is: why not encode and decode the query string? AFAIK this prevents data loss.

My suggestion is to apply the below patch. I encoded according to RFC3986, as this is used by `rawurl*code()`.

```diff
diff --git a/src/Post/PostBody.php b/src/Post/PostBody.php
index 2848db6..2c4a50e 100644
--- a/src/Post/PostBody.php
+++ b/src/Post/PostBody.php
@@ -257,14 +257,14 @@ class PostBody implements PostBodyInterface
$fields = [];
} else {
$query = (string) (new Query($this->fields))
- ->setEncodingType(false)
+ ->setEncodingType(Query::RFC3986)
->setAggregator($this->getAggregator());

// Convert the flattened query string back into an array
$fields = [];
foreach (explode('&', $query) as $kvp) {
$parts = explode('=', $kvp, 2);
- $fields[$parts[0]] = isset($parts[1]) ? $parts[1] : null;
+ $fields[rawurldecode($parts[0])] = isset($parts[1]) ? rawurldecode($parts[1]) : null;
}
}
```