From: Ardis Lu Date: Fri, 17 Oct 2025 06:52:43 +0000 (-0700) Subject: Fix regression where `null` and `undefined` are unable to be denormalized X-Git-Tag: v0.1.8~8 X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=9710a1a2353dea5a6524bd3c52a00008ef0a11a1;p=csvio Fix regression where `null` and `undefined` are unable to be denormalized --- diff --git a/src/normalization.js b/src/normalization.js index ac7bc41..bc3cd09 100644 --- a/src/normalization.js +++ b/src/normalization.js @@ -389,7 +389,12 @@ export class CSVDenormalizer extends TransformStream { firstRow = false; controller.enqueue(chunk.map(f => f?.displayName ?? f.name)); } - controller.enqueue(chunk.map(f => f.value instanceof Date ? f.value.toISOString() : f.value.toString())); + controller.enqueue(chunk.map(f => { + if (f.value instanceof Date) { + return f.value.toISOString(); + } + return f.value?.toString?.() ?? ''; + })); } }); } diff --git a/test/normalization.test.js b/test/normalization.test.js index ce7bb72..d71e0ae 100644 --- a/test/normalization.test.js +++ b/test/normalization.test.js @@ -638,6 +638,30 @@ suite('CSVDenormalizer', { concurrency: true }, () => { ['a2', 'b2'] ])); }); + test('denormalizes null into empty string', { concurrency: true }, async () => { + await createCSVMockStream([ + [{ name: 'a', value: null }, { name: 'b', value: null }], + [{ name: 'a', value: null }, { name: 'b', value: null }], + ]) + .pipeThrough(new CSVDenormalizer()) + .pipeTo(csvStreamEqualWritable([ + ['a', 'b'], + ['', ''], + ['', ''] + ])); + }); + test('denormalizes undefined into empty string', { concurrency: true }, async () => { + await createCSVMockStream([ + [{ name: 'a', value: undefined }, { name: 'b', value: undefined }], + [{ name: 'a', value: undefined }, { name: 'b', value: undefined }], + ]) + .pipeThrough(new CSVDenormalizer()) + .pipeTo(csvStreamEqualWritable([ + ['a', 'b'], + ['', ''], + ['', ''] + ])); + }); test('works with instanceof', { concurrency: true }, async () => { const s = new CSVDenormalizer(); deepStrictEqual(s instanceof CSVDenormalizer, true);