diff options
-rw-r--r-- | src/AbstractCsv.php | 6 | ||||
-rw-r--r-- | test/CsvTest.php | 8 |
2 files changed, 11 insertions, 3 deletions
diff --git a/src/AbstractCsv.php b/src/AbstractCsv.php index 8f337f4..f50b049 100644 --- a/src/AbstractCsv.php +++ b/src/AbstractCsv.php @@ -320,9 +320,9 @@ abstract class AbstractCsv implements JsonSerializable, IteratorAggregate header('Content-Type: application/octet-stream'); header('Content-Transfer-Encoding: binary'); header('Content-Disposition: attachment; filename="'.rawurlencode($filename).'"'); - if ($this->bom_on_output) { - echo chr(239).chr(187).chr(191); - } + } + if ($this->bom_on_output) { + echo chr(239).chr(187).chr(191); } //@codeCoverageIgnoreEnd $iterator->rewind(); diff --git a/test/CsvTest.php b/test/CsvTest.php index 267790d..c488afb 100644 --- a/test/CsvTest.php +++ b/test/CsvTest.php @@ -112,6 +112,14 @@ class CsvTest extends PHPUnit_Framework_TestCase $this->assertTrue($this->csv->hasBOMOnOutput()); } + public function testAddBOMSequences() + { + $this->csv->setBOMOnOutput(true); + $expected = chr(239).chr(187).chr(191)."john,doe,john.doe@example.com".PHP_EOL + ."jane,doe,jane.doe@example.com".PHP_EOL; + $this->assertSame($expected, $this->csv->__toString()); + } + /** * @expectedException InvalidArgumentException * @expectedExceptionMessage `$nb_rows` must be a valid positive integer |