From 55f6f8b39b521f30656eb179e6791a0ff794f686 Mon Sep 17 00:00:00 2001 From: Jay Danielsen Date: Fri, 30 Aug 2024 12:10:08 -0400 Subject: [PATCH] fix for empty string handling --- lib/utils.js | 2 +- package.json | 2 +- test/test.js | 26 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 6a22455..b29a359 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -133,7 +133,7 @@ module.exports = { } else if (_.isBoolean(v)) { t = 'b'; v = '' + (v === true ? '1' : '0') + ''; - } else if (v) { + } else if (v !== undefined) { v = '' + escapeXML(v) + ''; t = 'inlineStr'; } diff --git a/package.json b/package.json index 9a79100..c8ae766 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@brandwatch/xlsx-stream", "description": "Creates SpreadsheetML (.xlsx) files in sequence with streaming interface.", - "version": "0.2.0", + "version": "0.2.1", "homepage": "https://github.com/BrandwatchLtd/node-xlsx-stream", "author": { "name": "Ryota Suzuki", diff --git a/test/test.js b/test/test.js index feaacc6..d02a775 100644 --- a/test/test.js +++ b/test/test.js @@ -168,6 +168,32 @@ describe("xlsx-stream", () => { }); }); + describe("empty string", () => { + const filePath = path.join(dirPath, "emptyString.xlsx"); + const expectedRows = [ + ['Place Holder', ''], + ]; + + it("should create an xlsx file and preserve empty string", (done) => { + const x = xlsx_stream(); + const out = fs.createWriteStream(filePath); + x.pipe(out); + expectedRows.forEach((row) => x.write(row)); + x.end(); + out.on("finish", () => { + const workSheetsFromFile = xlsx.parse(filePath); + const rows = workSheetsFromFile[0].data; + + assert.deepStrictEqual( + rows, + expectedRows, + `Rows do not match. Expected ${JSON.stringify(expectedRows)}, but got ${JSON.stringify(rows)}`, + ); + done(); + }); + }); + }); + describe("Large dataset", () => { it("should handle large dataset", (done) => { const randRows = 10000 + _.random(10000);