8000 Ensure end of line character presence · symfony/symfony@b6931ab · GitHub
[go: up one dir, main page]

Skip to content

Commit b6931ab

Browse files
author
Bizley
authored
Ensure end of line character presence
1 parent 9447827 commit b6931ab

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/Symfony/Component/Serializer/Encoder/CsvEncoder.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,20 @@ public function encode($data, string $format, array $context = [])
9494
unset($value);
9595

9696
$headers = array_merge(array_values($headers), array_diff($this->extractHeaders($data), $headers));
97-
97+
$endOfLine = $context[self::END_OF_LINE] ?? $this->defaultContext[self::END_OF_LINE];
98+
9899
if (!($context[self::NO_HEADERS_KEY] ?? $this->defaultContext[self::NO_HEADERS_KEY])) {
99100
fputcsv($handle, $headers, $delimiter, $enclosure, $escapeChar);
100-
if ("\n" !== ($context[self::END_OF_LINE] ?? $this->defaultContext[self::END_OF_LINE]) && 0 === fseek($handle, -1, \SEEK_CUR)) {
101-
fwrite($handle, $context[self::END_OF_LINE]);
101+
if ("\n" !== $endOfLine && 0 === fseek($handle, -1, \SEEK_CUR)) {
102+
fwrite($handle, $endOfLine);
102103
}
103104
}
104105

105106
$headers = array_fill_keys($headers, '');
106107
foreach ($data as $row) {
107108
fputcsv($handle, array_replace($headers, $row), $delimiter, $enclosure, $escapeChar);
108-
if ("\n" !== ($context[self::END_OF_LINE] ?? $this->defaultContext[self::END_OF_LINE]) && 0 === fseek($handle, -1, \SEEK_CUR)) {
109-
fwrite($handle, $context[self::END_OF_LINE]);
109+
if ("\n" !== $endOfLine && 0 === fseek($handle, -1, \SEEK_CUR)) {
110+
fwrite($handle, $endOfLine);
110111
}
111112
}
112113

0 commit comments

Comments
 (0)
0