Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
[hotfix/ZF-11878] Zend_Filter
Browse files Browse the repository at this point in the history
- fixed options name to equal same validator option
- fixed Alnum unittests
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 35 deletions.
54 changes: 21 additions & 33 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1136,41 +1136,29 @@ protected function prepareBody()

// If we have POST parameters or files, encode and add them to the body
if (count($this->getRequest()->post()->toArray()) > 0 || $totalFiles > 0) {
if (stripos($this->getEncType(), self::ENC_FORMDATA) === 0) {
$boundary = '---ZENDHTTPCLIENT-' . md5(microtime());
$this->setEncType(self::ENC_FORMDATA, $boundary);

// Get POST parameters and encode them
$params = self::flattenParametersArray($this->getRequest()->post()->toArray());
foreach ($params as $pp) {
$body .= $this->encodeFormData($boundary, $pp[0], $pp[1]);
}

switch($this->getEncType()) {
case self::ENC_FORMDATA:
// Encode body as multipart/form-data
$boundary = '---ZENDHTTPCLIENT-' . md5(microtime());
$this->setEncType(self::ENC_FORMDATA, $boundary);

// Get POST parameters and encode them
$params = self::flattenParametersArray($this->getRequest()->post()->toArray());
foreach ($params as $pp) {
$body .= $this->encodeFormData($boundary, $pp[0], $pp[1]);
}

// Encode files
foreach ($this->getRequest()->file()->toArray() as $key => $file) {
$fhead = array('Content-Type' => $file['ctype']);
$body .= $this->encodeFormData($boundary, $file['formname'], $file['data'], $file['filename'], $fhead);
}

$body .= "--{$boundary}--\r\n";
break;

case self::ENC_URLENCODED:
// Encode body as application/x-www-form-urlencoded
$body = http_build_query($this->getRequest()->post()->toArray());
break;

default:
if (isset($mbIntEnc)) {
mb_internal_encoding($mbIntEnc);
}

throw new Exception\RuntimeException("Cannot handle content type '{$this->encType}' automatically");
break;
// Encode files
foreach ($this->getRequest()->file()->toArray() as $key => $file) {
$fhead = array('Content-Type' => $file['ctype']);
$body .= $this->encodeFormData($boundary, $file['formname'], $file['data'], $file['filename'], $fhead);
}
$body .= "--{$boundary}--\r\n";
} elseif (stripos($this->getEncType(), self::ENC_URLENCODED) === 0) {
// Encode body as application/x-www-form-urlencoded
$body = http_build_query($this->getRequest()->post()->toArray());
} else {
throw new Exception\RuntimeException("Cannot handle content type '{$this->encType}' automatically");
}

}

if (isset($mbIntEnc)) {
Expand Down
25 changes: 23 additions & 2 deletions test/Client/CommonHttpTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,8 @@ public function testAbsolutePathRedirect()
$this->client->setConfig(array('maxredirects' => 1));

// Get the host and port part of our baseuri
$uri = $this->client->getUri()->getScheme() . '://' . $this->client->getUri()->getHost() . ':' .
$this->client->getUri()->getPort();
$port = ($this->client->getUri()->getPort() == 80) ? '' : ':' .$this->client->getUri()->getPort();
$uri = $this->client->getUri()->getScheme() . '://' . $this->client->getUri()->getHost() . $port;

$res = $this->client->send();

Expand Down Expand Up @@ -916,6 +916,27 @@ public function testZF9404DoubleContentLengthHeader()
$this->assertEquals($expect, strlen($response->getBody()));
}


/**
* @group ZF2-78
* @dataProvider parameterArrayProvider
*/
public function testContentTypeAdditionlInfo($params)
{
$this->client->setUri($this->baseuri . 'testPostData.php');
$this->client->setHeaders(array(
'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8'
));
$this->client->setMethod(\Zend\Http\Request::METHOD_POST);

$this->client->setParameterPost($params);

$this->client->send();

$res = $this->client->send();
$this->assertEquals(serialize($params), $res->getBody(), "POST data integrity test failed");
}

/**
* Internal helpder function to get the contents of test files
*
Expand Down

0 comments on commit 22ab842

Please sign in to comment.