Making HttpResponse more tolerant of line endings.

This commit is contained in:
mark_story 2011-11-08 19:23:36 -05:00
parent cfbc6d4989
commit 89ced25fad
2 changed files with 10 additions and 1 deletions

View file

@ -204,7 +204,7 @@ class HttpResponse implements ArrayAccess {
$chunkLength = null;
while ($chunkLength !== 0) {
if (!preg_match("/^([0-9a-f]+) *(?:;(.+)=(.+))?\r\n/iU", $body, $match)) {
if (!preg_match('/^([0-9a-f]+) *(?:;(.+)=(.+))?(?:\r\n|\n)/iU', $body, $match)) {
throw new SocketException(__d('cake_dev', 'HttpSocket::_decodeChunkedBody - Could not parse malformed chunk.'));
}

View file

@ -320,6 +320,15 @@ class HttpResponseTest extends CakeTestCase {
$r = $this->HttpResponse->decodeBody($sample['encoded'], $encoding);
$this->assertEquals($r, $sample['decoded']);
$encoding = 'chunked';
$sample = array(
'encoded' => "19\nThis is a chunked message\r\n0\n",
'decoded' => array('body' => "This is a chunked message", 'header' => false)
);
$r = $this->HttpResponse->decodeBody($sample['encoded'], $encoding);
$this->assertEquals($r, $sample['decoded'], 'Inconsistent line terminators should be tolerated.');
}
/**