(core) Fix JS error when pasting data with merged cells.

Summary:
Pasting data with merged cells from Excel (or from HTML tables with colspan/rowspan),
we used to get "Cannot read property 'displayValue' of undefined".

Fix it by assuming that some cell values may be empty.

Test Plan: Added test case reproduces the failure without the fix, and passes with.

Reviewers: alexmojaki

Reviewed By: alexmojaki

Differential Revision: https://phab.getgrist.com/D2990
This commit is contained in:
Dmitry S 2021-08-20 03:31:19 -04:00
parent 00c1a0c688
commit 572b59cc0c

View File

@ -369,9 +369,9 @@ BaseView.prototype._parsePasteForView = function(data, cols) {
_.isObject(data[0][0]) && data[0][0].hasOwnProperty('displayValue')) { _.isObject(data[0][0]) && data[0][0].hasOwnProperty('displayValue')) {
richData = data.map((col, idx) => { richData = data.map((col, idx) => {
if (col[0].colType === updateColTypes[idx]) { if (col[0].colType === updateColTypes[idx]) {
return col.map(v => v.hasOwnProperty('rawValue') ? v.rawValue : v.displayValue); return col.map(v => v && v.hasOwnProperty('rawValue') ? v.rawValue : v.displayValue);
} else { } else {
return col.map(v => v.displayValue); return col.map(v => v && v.displayValue);
} }
}); });
} }