Permalink
Browse files

Making HttpResponse more tolerant of line endings.

  • Loading branch information...
1 parent cfbc6d4 commit 89ced25fad2d1d90580296f2728b078724d79007 @markstory markstory committed Nov 9, 2011
Showing with 10 additions and 1 deletion.
  1. +1 −1 lib/Cake/Network/Http/HttpResponse.php
  2. +9 −0 lib/Cake/Test/Case/Network/Http/HttpResponseTest.php
@@ -204,7 +204,7 @@ protected function _decodeChunkedBody($body) {
$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.'));
}
@@ -320,6 +320,15 @@ public function testDecodeBody() {
$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.');
}
/**

0 comments on commit 89ced25

Please sign in to comment.