Skip to content

Commit

Permalink
Revert line-ending detection
Browse files Browse the repository at this point in the history
No idea whether it is related to the current mess that is PHP memory
streams, but Travis is reporting that this is not working properly on
the two versions of PHP (5.4, 5.6) that I don't have installed.
  • Loading branch information
slusarz committed Feb 10, 2015
1 parent 1477dcd commit 61f3301
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 44 deletions.
34 changes: 2 additions & 32 deletions framework/Mime/lib/Horde/Mime/Filter/Encoding.php
Expand Up @@ -25,14 +25,7 @@
class Horde_Mime_Filter_Encoding extends php_user_filter
{
/**
* Location of last CR character.
*
* @var integer
*/
protected $_cr = null;

/**
* Non CR/LF characters.
* Number of consecutive non-CR/LF characters.
*
* @var integer
*/
Expand All @@ -53,10 +46,8 @@ public function onCreate()
*/
public function filter($in, $out, &$consumed, $closing)
{
$skip = ($this->params->body !== false);

while ($bucket = stream_bucket_make_writeable($in)) {
if (!$skip) {
if ($this->params->body !== 'binary') {
$len = $bucket->datalen;
$str = $bucket->data;

Expand All @@ -67,24 +58,10 @@ public function filter($in, $out, &$consumed, $closing)
case 0:
/* Only binary data can have NULLs. */
$this->params->body = 'binary';
$skip = true;
break 2;

case 10: // LF
if (($this->_cr !== ($i - 1)) &&
!$this->params->body) {
$this->params->body = '8bit_noncrlf';
}
$this->_cr = null;
$this->_crlf = 0;
break;

case 13: // CR
if (is_null($this->_cr)) {
$this->_cr = $i;
} elseif (!$this->params->body) {
$this->params->body = '8bit_noncrlf';
}
$this->_crlf = 0;
break;

Expand All @@ -94,7 +71,6 @@ public function filter($in, $out, &$consumed, $closing)
* binary. */
if (++$this->_crlf > 998) {
$this->params->body = 'binary';
$skip = true;
break 2;
} else if ($chr > 127) {
$this->params->body = '8bit';
Expand All @@ -108,12 +84,6 @@ public function filter($in, $out, &$consumed, $closing)
stream_bucket_append($out, $bucket);
}

if ($closing &&
!is_null($this->_cr) &&
!$this->params->body) {
$this->params->body = '8bit_noncrlf';
}

return PSFS_PASS_ON;
}

Expand Down
28 changes: 16 additions & 12 deletions framework/Mime/test/Horde/Mime/Filter/EncodingTest.php
Expand Up @@ -62,28 +62,32 @@ public function bodyFilterProvider()
false
),
array(
"This is 8-bit åå\r\ndata.",
'8bit'
"This is 7-bit\rdata\rwith\rCR\rline-endings.",
false,
),
array(
str_repeat('A', 900) . "This is also 8-bit åå\r\ndata.",
'8bit'
"This is 7-bit\ndata\nwith\nLF\nline-endings.",
false
),
array(
"This is 7-bit\r\ndata\nwith\rinconsistent\r\nline-endings.",
false
),
array(
"This is 8-bit\ndata\nwith\nnon-CRLF\nline-endings.",
'8bit_noncrlf'
"This is 8-bit åå\r\ndata.",
'8bit'
),
array(
"This is 8-bit data with a terminal CR.\r",
'8bit_noncrlf'
str_repeat('A', 900) . "This is also 8-bit åå\r\ndata.",
'8bit'
),
array(
"This is 8-bit\rdata\rwith\rnon-CRLF\rline-endings.",
'8bit_noncrlf'
"This is 8-bit åå\rdata\rwith\rCR\rline-endings.",
'8bit'
),
array(
"This is 8-bit\r\ndata\nwith\rinconsistent\r\nline-endings.",
'8bit_noncrlf'
"This is 8-bit åå\ndata\nwith\nLF\nline-endings.",
'8bit'
),
array(
"This is binary \0\r\ndata.",
Expand Down

0 comments on commit 61f3301

Please sign in to comment.