From 268bb42a029de70767d1ca4a6c7f44c5d884fbfb Mon Sep 17 00:00:00 2001 From: the_undefined Date: Mon, 5 May 2008 12:42:15 +0000 Subject: [PATCH] Made HttpSocket::decodeChunkedBody a little more forgiving, fixes #4523 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6752 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/http_socket.php | 2 +- cake/tests/cases/libs/http_socket.test.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cake/libs/http_socket.php b/cake/libs/http_socket.php index a8c04a123..4b1bf3ac5 100644 --- a/cake/libs/http_socket.php +++ b/cake/libs/http_socket.php @@ -469,7 +469,7 @@ class HttpSocket extends CakeSocket { $chunkLength = null; while ($chunkLength !== 0) { - if (!preg_match("/^([0-9a-f]+)(?:;(.+)=(.+))?\r\n/iU", $body, $match)) { + if (!preg_match("/^([0-9a-f]+) *(?:;(.+)=(.+))?\r\n/iU", $body, $match)) { if (!$this->quirksMode) { trigger_error(__('HttpSocket::decodeChunkedBody - Could not parse malformed chunk. Activate quirks mode to do this.', true), E_USER_WARNING); return false; diff --git a/cake/tests/cases/libs/http_socket.test.php b/cake/tests/cases/libs/http_socket.test.php index ec4062f9e..58bfb71cb 100644 --- a/cake/tests/cases/libs/http_socket.test.php +++ b/cake/tests/cases/libs/http_socket.test.php @@ -639,6 +639,10 @@ class HttpSocketTest extends UnitTestCase { $this->assertIdentical($r['body'], $decoded); $this->assertIdentical($r['header'], false); + $encoded = "19 \r\nThis is a chunked message\r\n0\r\n"; + $r = $this->Socket->decodeChunkedBody($encoded); + $this->assertIdentical($r['body'], $decoded); + $encoded = "19\r\nThis is a chunked message\r\nE\r\n\nThat is cool\n\r\n0\r\n"; $decoded = "This is a chunked message\nThat is cool\n"; $r = $this->Socket->decodeChunkedBody($encoded);