From e0fc89246aff858ac1de8950a1e3b1dd8c3e6c65 Mon Sep 17 00:00:00 2001 From: reviewher <24845478+reviewher@users.noreply.github.com> Date: Tue, 5 Apr 2022 19:14:12 -0700 Subject: [PATCH] Fix bad google sheets format 'd.m' --- bits/11_ssfutils.js | 9 +++++++++ bits/47_styxml.js | 2 +- bits/48_stybin.js | 2 +- bits/66_wscommon.js | 4 ++-- bits/75_xlml.js | 2 +- bits/76_xls.js | 6 +++--- 6 files changed, 17 insertions(+), 8 deletions(-) diff --git a/bits/11_ssfutils.js b/bits/11_ssfutils.js index 1e50446..2799260 100644 --- a/bits/11_ssfutils.js +++ b/bits/11_ssfutils.js @@ -65,3 +65,12 @@ function dateNF_fix(str/*:string*/, dateNF/*:string*/, match/*:Array*/)/ return datestr + "T" + timestr; } +/* table of bad formats written by third-party tools */ +var bad_formats = { + "d.m": "d\\.m" // Issue #2571 Google Sheets writes invalid format 'd.m', correct format is 'd"."m' or 'd\\.m' +}; + +function SSF__load(fmt, idx) { + return SSF_load(bad_formats[fmt] || fmt, idx); +} + diff --git a/bits/47_styxml.js b/bits/47_styxml.js index 90f317f..a5d2a1d 100644 --- a/bits/47_styxml.js +++ b/bits/47_styxml.js @@ -278,7 +278,7 @@ function parse_numFmts(t, styles, opts) { for(j = 0x188; j > 0x3c; --j) if(styles.NumberFmt[j] == null) break; styles.NumberFmt[j] = f; } - SSF_load(f,j); + SSF__load(f,j); } } break; case '': break; diff --git a/bits/48_stybin.js b/bits/48_stybin.js index 19251d7..f220a7d 100644 --- a/bits/48_stybin.js +++ b/bits/48_stybin.js @@ -215,7 +215,7 @@ function parse_sty_bin(data, themes, opts) { recordhopper(data, function hopper_sty(val, R, RT) { switch(RT) { case 0x002C: /* BrtFmt */ - styles.NumberFmt[val[0]] = val[1]; SSF_load(val[1], val[0]); + styles.NumberFmt[val[0]] = val[1]; SSF__load(val[1], val[0]); break; case 0x002B: /* BrtFont */ styles.Fonts.push(val); diff --git a/bits/66_wscommon.js b/bits/66_wscommon.js index 32efda2..e148b71 100644 --- a/bits/66_wscommon.js +++ b/bits/66_wscommon.js @@ -62,7 +62,7 @@ function get_cell_style(styles/*:Array*/, cell/*:Cell*/, opts) { var i = 0x3c, len = styles.length; if(z == null && opts.ssf) { for(; i < 0x188; ++i) if(opts.ssf[i] == null) { - SSF_load(cell.z, i); + SSF__load(cell.z, i); // $FlowIgnore opts.ssf[i] = cell.z; opts.revssf[cell.z] = z = i; @@ -88,7 +88,7 @@ function safe_format(p/*:Cell*/, fmtid/*:number*/, fillid/*:?number*/, opts, the if(p.t === 'z' && !opts.cellStyles) return; if(p.t === 'd' && typeof p.v === 'string') p.v = parseDate(p.v); if((!opts || opts.cellText !== false) && p.t !== 'z') try { - if(table_fmt[fmtid] == null) SSF_load(SSFImplicit[fmtid] || "General", fmtid); + if(table_fmt[fmtid] == null) SSF__load(SSFImplicit[fmtid] || "General", fmtid); if(p.t === 'e') p.w = p.w || BErr[p.v]; else if(fmtid === 0) { if(p.t === 'n') { diff --git a/bits/75_xlml.js b/bits/75_xlml.js index bafdfb0..a4f334d 100644 --- a/bits/75_xlml.js +++ b/bits/75_xlml.js @@ -343,7 +343,7 @@ function parse_xlml_xml(d, _opts)/*:Workbook*/ { stag.nf = unescapexml(xlml_parsexmltag(Rn[0]).Format || "General"); if(XLMLFormatMap[stag.nf]) stag.nf = XLMLFormatMap[stag.nf]; for(var ssfidx = 0; ssfidx != 0x188; ++ssfidx) if(table_fmt[ssfidx] == stag.nf) break; - if(ssfidx == 0x188) for(ssfidx = 0x39; ssfidx != 0x188; ++ssfidx) if(table_fmt[ssfidx] == null) { SSF_load(stag.nf, ssfidx); break; } + if(ssfidx == 0x188) for(ssfidx = 0x39; ssfidx != 0x188; ++ssfidx) if(table_fmt[ssfidx] == null) { SSF__load(stag.nf, ssfidx); break; } break; case 'column' /*case 'Column'*/: diff --git a/bits/76_xls.js b/bits/76_xls.js index 049026d..a447f5c 100644 --- a/bits/76_xls.js +++ b/bits/76_xls.js @@ -488,14 +488,14 @@ function parse_workbook(blob, options/*:ParseOpts*/)/*:Workbook*/ { if(opts.biff == 4) { BIFF2FmtTable[BIFF2Fmt++] = val[1]; for(var b4idx = 0; b4idx < BIFF2Fmt + 163; ++b4idx) if(table_fmt[b4idx] == val[1]) break; - if(b4idx >= 163) SSF_load(val[1], BIFF2Fmt + 163); + if(b4idx >= 163) SSF__load(val[1], BIFF2Fmt + 163); } - else SSF_load(val[1], val[0]); + else SSF__load(val[1], val[0]); } break; case 0x001e /* BIFF2FORMAT */: { BIFF2FmtTable[BIFF2Fmt++] = val; for(var b2idx = 0; b2idx < BIFF2Fmt + 163; ++b2idx) if(table_fmt[b2idx] == val) break; - if(b2idx >= 163) SSF_load(val, BIFF2Fmt + 163); + if(b2idx >= 163) SSF__load(val, BIFF2Fmt + 163); } break; case 0x00e5 /* MergeCells */: merges = merges.concat(val); break;