From 9710a1a2353dea5a6524bd3c52a00008ef0a11a1 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Thu, 16 Oct 2025 23:52:43 -0700 Subject: [PATCH] Fix regression where `null` and `undefined` are unable to be denormalized --- src/normalization.js | 7 ++++++- test/normalization.test.js | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) 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); -- 2.47.3