diff --git a/.gitignore b/.gitignore index a73932c0..42894e5f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ .idea +.php_cs.cache +.phpunit.result.cache build composer.lock docs/_site vendor /nbproject/private/ -.php_cs.cache diff --git a/CHANGELOG.md b/CHANGELOG.md index e41bc898..e78a4b2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,8 @@ All Notable changes to `Csv` will be documented in this file ### Fixed -- Nothing +- `AbstractCSV::chunk` see [#325](https://github.com/thephpleague/csv/pull/325) remove CSV flags from the Stream class to avoid infinite loop. +- Internal improve `HTMLConverter`. ### Removed diff --git a/phpstan.src.neon b/phpstan.src.neon index 96d0543a..87cca5c6 100644 --- a/phpstan.src.neon +++ b/phpstan.src.neon @@ -1,2 +1,5 @@ includes: - vendor/phpstan/phpstan-strict-rules/rules.neon +parameters: + ignoreErrors: + reportUnmatchedIgnoredErrors: false \ No newline at end of file diff --git a/src/AbstractCsv.php b/src/AbstractCsv.php index 1eae1d73..e7e33520 100644 --- a/src/AbstractCsv.php +++ b/src/AbstractCsv.php @@ -262,6 +262,7 @@ public function chunk(int $length): Generator $input_bom = $this->getInputBOM(); $this->document->rewind(); + $this->document->setFlags(0); $this->document->fseek(strlen($input_bom)); foreach (str_split($this->output_bom.$this->document->fread($length), $length) as $chunk) { yield $chunk; diff --git a/src/HTMLConverter.php b/src/HTMLConverter.php index 4490919f..27b7c644 100644 --- a/src/HTMLConverter.php +++ b/src/HTMLConverter.php @@ -13,6 +13,8 @@ namespace League\Csv; +use DOMDocument; +use DOMElement; use DOMException; use Traversable; use function preg_match; @@ -60,11 +62,15 @@ public function __construct() */ public function convert($records): string { + /** @var DOMDocument $doc */ $doc = $this->xml_converter->convert($records); - $doc->documentElement->setAttribute('class', $this->class_name); - $doc->documentElement->setAttribute('id', $this->id_value); - return $doc->saveHTML($doc->documentElement); + /** @var DOMElement $table */ + $table = $doc->getElementsByTagName('table')->item(0); + $table->setAttribute('class', $this->class_name); + $table->setAttribute('id', $this->id_value); + + return $doc->saveHTML($table); } /** diff --git a/tests/CsvTest.php b/tests/CsvTest.php index 420aba49..a0fa3a3b 100644 --- a/tests/CsvTest.php +++ b/tests/CsvTest.php @@ -172,6 +172,18 @@ public function testOutputHeaders() self::assertContains('Content-Disposition: attachment; filename="tst.csv"; filename*=utf-8\'\'t%C3%A9st.csv', $headers[3]); } + /** + * @covers ::chunk + * @covers ::getContent + */ + public function testChunkDoesNotTimeoutAfterReading() + { + $raw_csv = "john,doe,john.doe@example.com\njane,doe,jane.doe@example.com\n"; + $csv = Reader::createFromString($raw_csv); + iterator_to_array($csv->getRecords()); + self::assertSame($raw_csv, $csv->getContent()); + } + /** * @covers ::__toString * @covers ::getContent