Skip to content

Commit ec22202

Browse files
authored
Merge pull request #1344 from Alanscut/issue_1339
[bugfix] Fix special cell values causing invalid files produced(#1339)
2 parents 99074f7 + a606046 commit ec22202

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

lib/utils/shared-strings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class SharedStrings {
22
constructor() {
33
this._values = [];
44
this._totalRefs = 0;
5-
this._hash = {};
5+
this._hash = Object.create(null);
66
}
77

88
get count() {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const ExcelJS = verquire('exceljs');
2+
3+
// this file to contain integration tests created from github issues
4+
const TEST_XLSX_FILE_NAME = './spec/out/wb.test.xlsx';
5+
6+
describe('github issues', () => {
7+
it('issue 1339 - Special cell value results invalid file', async () => {
8+
const wb = new ExcelJS.stream.xlsx.WorkbookWriter({
9+
filename: TEST_XLSX_FILE_NAME,
10+
useStyles: true,
11+
useSharedStrings: true,
12+
});
13+
const ws = wb.addWorksheet('Sheet1');
14+
const specialValues = [
15+
'constructor',
16+
'hasOwnProperty',
17+
'isPrototypeOf',
18+
'propertyIsEnumerable',
19+
'toLocaleString',
20+
'toString',
21+
'valueOf',
22+
'__defineGetter__',
23+
'__defineSetter__',
24+
'__lookupGetter__',
25+
'__lookupSetter__',
26+
'__proto__',
27+
];
28+
for (let i = 0, len = specialValues.length; i < len; i++) {
29+
const value = specialValues[i];
30+
ws.addRow([value]);
31+
ws.getCell(`B${i + 1}`).value = value;
32+
}
33+
await wb.commit();
34+
const wb2 = new ExcelJS.Workbook();
35+
await wb2.xlsx.readFile(TEST_XLSX_FILE_NAME);
36+
const ws2 = wb2.getWorksheet('Sheet1');
37+
for (let i = 0, len = specialValues.length; i < len; i++) {
38+
const value = specialValues[i];
39+
expect(ws2.getCell(`A${i + 1}`).value).to.equal(value);
40+
expect(ws2.getCell(`B${i + 1}`).value).to.equal(value);
41+
}
42+
});
43+
});

0 commit comments

Comments
 (0)