Skip to content

Commit

Permalink
Fixed htmlToGridSettings helper (#7315)
Browse files Browse the repository at this point in the history
* #7311 - Fixes throwing errors if a table has no rows in htmlToGridSettings helper. Adds test spec for that behaviour.

* #7311 - Adds CHANGELOG entry. Adjusts code after linter check.
  • Loading branch information
swistach committed Oct 21, 2020
1 parent 6ae4d8d commit dcaaccb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Fixed a problem with data being pasted with an offset compensating the number of previously hidden rows/columns. [#6742](https://github.com/handsontable/handsontable/issues/6742)
- Fixed an issue the container not being updated after trimming rows. [#7241](https://github.com/handsontable/handsontable/issues/7241)
- Fixed an issue with a `htmlToGridSettings` helper if passed `<table>` had no rows. [#7311](https://github.com/handsontable/handsontable/issues/7311)
- Fixed an issue where sorting indicator moved incorrectly when column was added. [#6397](https://github.com/handsontable/handsontable/issues/6397)
- Fixed a bug, where untrimming previously trimmed rows would sometimes result in the table instance not refreshing its height, leaving the row headers not properly rendered. [#6276](https://github.com/handsontable/handsontable/issues/6276)
- Fix a problem when `event.target`'s parent in the `mouseover` event was not defined, the table threw an error when hovering over row/column headers. [#6926](https://github.com/handsontable/handsontable/issues/6926)
Expand Down
3 changes: 2 additions & 1 deletion src/utils/parseTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ export function htmlToGridSettings(element, rootDocument = document) {

const generator = tempElem.querySelector('meta[name$="enerator"]');
const hasRowHeaders = checkElement.querySelector('tbody th') !== null;
const countCols = Array.from(checkElement.querySelector('tr').cells)
const trElement = checkElement.querySelector('tr');
const countCols = !trElement ? 0 : Array.from(trElement.cells)
.reduce((cols, cell) => cols + cell.colSpan, 0) - (hasRowHeaders ? 1 : 0);
const fixedRowsBottom = checkElement.tFoot && Array.from(checkElement.tFoot.rows) || [];
const fixedRowsTop = [];
Expand Down
10 changes: 10 additions & 0 deletions test/unit/utils/parseTable.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ describe('htmlToGridSettings', () => {
expect(config.data.toString()).toBe('A3,B3,C3,A4,B4,C4,A5,B5,C5,A6,B6,C6');
});

it('should parse an empty HTML table to an empty config object', () => {
const tableInnerHTML = [
'<table><tbody>',
'</tbody></table>',
].join('');
const config = htmlToGridSettings(tableInnerHTML);

expect(config).toEqual({});
});

it('should parse data with special characters', () => {
const tableInnerHTML = [
'<table><tbody>',
Expand Down

0 comments on commit dcaaccb

Please sign in to comment.