Browse Source

Making HttpResponse more tolerant of line endings.

mark_story 14 years ago
parent
commit
89ced25fad

+ 1 - 1
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.'));
 			}
 

+ 9 - 0
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.');
 	}
 
 /**