]> git.ardis.lu - csvio/commitdiff
Fix regression where `null` and `undefined` are unable to be denormalized
authorArdis Lu <ardisglu@gmail.com>
Fri, 17 Oct 2025 06:52:43 +0000 (23:52 -0700)
committerArdis Lu <ardisglu@gmail.com>
Fri, 17 Oct 2025 06:52:43 +0000 (23:52 -0700)
src/normalization.js
test/normalization.test.js

index ac7bc41094dcb58cb6fa0c2bf71a89231461a72e..bc3cd09b02f9edb5ffe91cac7044a16955bc1437 100644 (file)
@@ -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?.() ?? '';
+        }));
       }
     });
   }
index ce7bb725afdb2bb2ce6160a0e83ffe3e16742bff..d71e0ae094da26e526d715f24684541d97bcb585 100644 (file)
@@ -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);
This page took 0.038728 seconds and 4 git commands to generate.