Skip to content

Commit bcf587f

Browse files
committed
bug swiftmailer#458 Fix Swift_ByteStream_FileByteStream::read to match to the specification. (realityking)
This PR was merged into the 5.1-dev branch. Discussion ---------- Fix Swift_ByteStream_FileByteStream::read to match to the specification. Issue discovered in swiftmailer#418 An explanation for the PHP behavior can be found here: http://us1.php.net/manual/en/function.feof.php#67261 Commits ------- f497b2e Fix Swift_ByteStream_FileByteStream::read to match to the specification.
2 parents 4f7a8b3 + f497b2e commit bcf587f

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/classes/Swift/ByteStream/FileByteStream.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function getPath()
7777
*
7878
* @param integer $length
7979
*
80-
* @return string
80+
* @return string|boolean
8181
*
8282
* @throws Swift_IoException
8383
*/
@@ -93,13 +93,21 @@ public function read($length)
9393
ini_set('magic_quotes_runtime', 1);
9494
}
9595
$this->_offset = ftell($fp);
96+
97+
// If we read one byte after reaching the end of the file
98+
// feof() will return false and an empty string is returned
99+
if ($bytes === '' && feof($fp)) {
100+
$this->_resetReadHandle();
101+
102+
return false;
103+
}
96104

97105
return $bytes;
98-
} else {
99-
$this->_resetReadHandle();
100-
101-
return false;
102106
}
107+
108+
$this->_resetReadHandle();
109+
110+
return false;
103111
}
104112

105113
/**

0 commit comments

Comments
 (0)