Skip to content

Commit fe6a1b4

Browse files
committed
Use Object.create(null)
1 parent b1e810b commit fe6a1b4

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/xlsx.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,12 @@ function extract(sheet, {range, headers} = {}) {
3434

3535
const output = new Array(r1 - r0 + 1);
3636
for (let r = r0; r <= r1; r++) {
37-
// Should we be using Object.create(null) instead of an empty object here?
38-
const row = (output[r - r0] = Object.defineProperty({}, "#", { // what is this non-enumerable row["#"] property for?
39-
value: r + 1,
40-
}));
37+
const row = (output[r - r0] = Object.create(null, {"#": {value: r + 1}}));
4138
const _row = sheet._rows[r]; // is this an internal ExcelJS API? why not sheet.getRow(r)?
4239
if (_row && _row.hasValues)
4340
for (let c = c0; c <= c1; c++) {
4441
const value = valueOf(_row._cells[c]); // internal ExcelJS API?
45-
if (value != null) row[names[c + 1]] = value; // what if the name is “__proto__” e.g.?
42+
if (value != null) row[names[c + 1]] = value;
4643
}
4744
}
4845

test/xlsx-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,13 @@ test("FileAttachment.xlsx derives column names such as A AA AAA…", (t) => {
276276
);
277277
t.end();
278278
});
279+
280+
test("FileAttachment.sheet headers protects __proto__ of row objects", (t) => {
281+
const workbook = new Workbook(
282+
mockWorkbook({
283+
Sheet1: [["__proto__"], [{a: 1}]],
284+
})
285+
);
286+
t.notEqual(workbook.sheet(0, {headers: true})[0].a, 1);
287+
t.end();
288+
});

0 commit comments

Comments
 (0)