From b3793e2ea7ee6a6726e619373b1c287819fe7e2e Mon Sep 17 00:00:00 2001 From: KurtMar Date: Wed, 9 Mar 2022 22:24:43 +0200 Subject: [PATCH] HTML Parsing fix misaligned cells (fixes #1621) --- bits/79_html.js | 2 +- test.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/bits/79_html.js b/bits/79_html.js index 4867930..c341e69 100644 --- a/bits/79_html.js +++ b/bits/79_html.js @@ -38,7 +38,7 @@ var HTML_ = (function() { m = htmldecode(m); if(range.s.r > R) range.s.r = R; if(range.e.r < R) range.e.r = R; if(range.s.c > C) range.s.c = C; if(range.e.c < C) range.e.c = C; - if(!m.length) continue; + if(!m.length) { C += CS; continue; } var o/*:Cell*/ = {t:'s', v:m}; if(opts.raw || !m.trim().length || _t == 's'){} else if(m === 'TRUE') o = {t:'b', v:true}; diff --git a/test.js b/test.js index c52e8ad..713307c 100644 --- a/test.js +++ b/test.js @@ -2286,6 +2286,20 @@ describe('HTML', function() { assert.equal(X.utils.sheet_to_csv(ws), "A,B\n1,2\n3,4\n4,6"); }); }); + describe('empty cell containing html element should increment cell index', function() { + var html = "
abc def
"; + var expectedCellCount = 3; + it('HTML string', function() { + var ws = X.read(html, {type:'string'}).Sheets.Sheet1; + var range = X.utils.decode_range(ws['!ref']); + assert.equal(range.e.c,expectedCellCount - 1); + }); + if(domtest) it('DOM', function() { + var ws = X.utils.table_to_sheet(get_dom_element(html)); + var range = X.utils.decode_range(ws['!ref']); + assert.equal(range.e.c, expectedCellCount - 1); + }); + }); }); describe('js -> file -> js', function() {