From 89ced25fad2d1d90580296f2728b078724d79007 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 8 Nov 2011 19:23:36 -0500 Subject: [PATCH] Making HttpResponse more tolerant of line endings. --- lib/Cake/Network/Http/HttpResponse.php | 2 +- lib/Cake/Test/Case/Network/Http/HttpResponseTest.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Network/Http/HttpResponse.php b/lib/Cake/Network/Http/HttpResponse.php index f921aad1b..c0f757bea 100644 --- a/lib/Cake/Network/Http/HttpResponse.php +++ b/lib/Cake/Network/Http/HttpResponse.php @@ -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.')); } diff --git a/lib/Cake/Test/Case/Network/Http/HttpResponseTest.php b/lib/Cake/Test/Case/Network/Http/HttpResponseTest.php index 23d51c77a..734519242 100644 --- a/lib/Cake/Test/Case/Network/Http/HttpResponseTest.php +++ b/lib/Cake/Test/Case/Network/Http/HttpResponseTest.php @@ -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.'); } /**