Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] Fix special cell values causing invalid files produced #1278

Merged
merged 1 commit into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/xlsx/xform/strings/shared-strings-xform.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 10,8 @@ class SharedStringsXform extends BaseXform {
values: [],
count: 0,
};
this.hash = {};
this.rich = {};
this.hash = Object.create(null);
this.rich = Object.create(null);
}

get sharedStringXform() {
Expand Down
44 changes: 44 additions & 0 deletions spec/integration/issues/issue-703-speciel-cell-file.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 1,44 @@
const ExcelJS = verquire('exceljs');

// this file to contain integration tests created from github issues
const TEST_XLSX_FILE_NAME = './spec/out/wb.test.xlsx';

describe('github issues', () => {
it('issue 703 - Special cell value results invalid file', () => {
const wb = new ExcelJS.Workbook();
const ws = wb.addWorksheet('Sheet1');
const specialValues = [
'constructor',
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'toLocaleString',
'toString',
'valueOf',
'__defineGetter__',
'__defineSetter__',
'__lookupGetter__',
'__lookupSetter__',
'__proto__',
];
for (let i = 0; i < specialValues.length; i ) {
const value = specialValues[i];
ws.addRow([value]);
ws.getCell(`B${i 1}`).value = value;
}
return wb.xlsx
.writeFile(TEST_XLSX_FILE_NAME)
.then(() => {
const wb2 = new ExcelJS.Workbook();
return wb2.xlsx.readFile(TEST_XLSX_FILE_NAME);
})
.then(wb2 => {
const ws2 = wb2.getWorksheet('Sheet1');
for (let i = 0; i < specialValues.length; i ) {
const value = specialValues[i];
expect(ws2.getCell(`A${i 1}`).value).to.equal(value);
expect(ws2.getCell(`B${i 1}`).value).to.equal(value);
}
});
});
});