-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] writeToStream / writeToPath emits empty output following empty rows #503
Comments
Looking at this a bit more, I suspect the issue might be something related to the When we get to RowFormatter.ts, it is changing I also tried settings Test case: // packages/format/__tests__/issues/issue503.spec.ts
import { RecordingStream } from '../__fixtures__';
import { RowArray, write } from '../../src';
describe('Issue #503 - https://github.com/C2FO/fast-csv/issues/503', () => {
it('should emit all columns after an empty row', () => {
return new Promise((res, rej) => {
const rs = new RecordingStream();
const data: RowArray[] = [[], ['something']];
write(data, { quote: false, headers: false, writeHeaders: false })
.pipe(rs)
.on('error', rej)
.on('finish', () => {
expect(rs.data.join('')).toBe('\nsomething');
res();
});
});
});
it('should not assume first row is a header if header = false', () => {
return new Promise((res, rej) => {
const rs = new RecordingStream();
const data: RowArray[] = [['1'], [], ['1', '2', '3']];
write(data, { quote: false, headers: false, writeHeaders: false })
.pipe(rs)
.on('error', rej)
.on('finish', () => {
expect(rs.data.join('')).toBe('1\n\n1,2,3');
res();
});
});
});
}); |
@robations I think I narrowed it down to https://github.com/C2FO/fast-csv/blob/master/packages/format/src/formatter/RowFormatter.ts#L135 I'm going to play with this since I'll have to handle the case where a row is an array of objects, hash arrays or a one dimensional array. Thank you for the test case that is really useful! |
@doug-martin no probs, and thanks for checking this out. |
* Fixes issue where row contents were ignored if the first row is empty and headers is false
* Fixes issue where row contents were ignored if the first row is empty and headers is false
@robations fixed and published under |
Describe the bug
When writing to a stream with an empty row and one or more rows with data, instead of writing the rows provided, writeToStream and writeToPath emits empty rows for each line. Not sure if intended but this seems to be a change in behaviour from v2 and feels like an unexpected outcome.
It might be slightly non-standard, but I'm working with a CSV file where the number of columns may change throughout the file.
Parsing or Formatting?
To Reproduce
Steps to reproduce the behavior:
ts-node test.ts && cat space-oddity.csv
The same thing happens with writeToStream.
Expected behavior
Expected output:
Screenshots
n/a
Desktop (please complete the following information):
Additional context
Let me know if you need any more info. I tried to step through the source code with the debugger, but the line numbers were pretty mangled so it wasn't clear what was happening when.
The text was updated successfully, but these errors were encountered: