From 4a31cb9810ff6fdb3a36a3259dc712c4a5941073 Mon Sep 17 00:00:00 2001 From: SheetJS Date: Wed, 22 Jun 2022 15:58:22 -0400 Subject: [PATCH] warn on codepage override in mini build [ci skip] --- bits/40_harb.js | 4 ++-- bits/67_wsxml.js | 2 +- bits/71_wbcommon.js | 2 +- bits/87_read.js | 3 ++- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/bits/40_harb.js b/bits/40_harb.js index 1eef6df..de95b76 100644 --- a/bits/40_harb.js +++ b/bits/40_harb.js @@ -119,7 +119,7 @@ function dbf_to_aoa(buf, opts)/*:AOA*/ { var ww = l7 ? 32 : 11; while(d.l < hend && d[d.l] != 0x0d) { field = ({}/*:any*/); - field.name = $cptable.utils.decode(current_cp, d.slice(d.l, d.l+ww)).replace(/[\u0000\r\n].*$/g,""); + field.name = (typeof $cptable !== "undefined" ? $cptable.utils.decode(current_cp, d.slice(d.l, d.l+ww)) : a2s(d.slice(d.l, d.l + ww))).replace(/[\u0000\r\n].*$/g,""); d.l += ww; field.type = String.fromCharCode(d.read_shift(1)); if(ft != 0x02 && !l7) field.offset = d.read_shift(4); @@ -173,7 +173,7 @@ function dbf_to_aoa(buf, opts)/*:AOA*/ { for(C = 0; C != fields.length; ++C) { var dd = d.slice(d.l, d.l+fields[C].len); d.l+=fields[C].len; prep_blob(dd, 0); - var s = $cptable.utils.decode(current_cp, dd); + var s = typeof $cptable !== "undefined" ? $cptable.utils.decode(current_cp, dd) : a2s(dd); switch(fields[C].type) { case 'C': // NOTE: it is conventional to write ' / / ' for empty dates diff --git a/bits/67_wsxml.js b/bits/67_wsxml.js index 9d61139..fe36787 100644 --- a/bits/67_wsxml.js +++ b/bits/67_wsxml.js @@ -258,7 +258,7 @@ function write_ws_xml_sheetviews(ws, opts, idx, wb)/*:string*/ { function write_ws_xml_cell(cell/*:Cell*/, ref, ws, opts/*::, idx, wb*/)/*:string*/ { if(cell.c) ws['!comments'].push([ref, cell.c]); - if(cell.v === undefined && typeof cell.f !== "string" || cell.t === 'z' && !cell.f) return ""; + if((cell.v === undefined || cell.t === "z" && !(opts||{}).sheetStubs) && typeof cell.f !== "string" && typeof cell.z == "undefined") return ""; var vv = ""; var oldt = cell.t, oldv = cell.v; if(cell.t !== "z") switch(cell.t) { diff --git a/bits/71_wbcommon.js b/bits/71_wbcommon.js index 17d0f4f..b749452 100644 --- a/bits/71_wbcommon.js +++ b/bits/71_wbcommon.js @@ -113,7 +113,7 @@ function safe1904(wb/*:Workbook*/)/*:string*/ { return parsexmlbool(wb.Workbook.WBProps.date1904) ? "true" : "false"; } -var badchars = /*#__PURE__*/"][*?\/\\".split(""); +var badchars = /*#__PURE__*/":][*?\/\\".split(""); function check_ws_name(n/*:string*/, safe/*:?boolean*/)/*:boolean*/ { if(n.length > 31) { if(safe) return false; throw new Error("Sheet names cannot exceed 31 chars"); } var _good = true; diff --git a/bits/87_read.js b/bits/87_read.js index a5773cd..19809f0 100644 --- a/bits/87_read.js +++ b/bits/87_read.js @@ -50,7 +50,7 @@ function read_plaintext_raw(data/*:RawData*/, o/*:ParseOpts*/)/*:Workbook*/ { function read_utf16(data/*:RawData*/, o/*:ParseOpts*/)/*:Workbook*/ { var d = data; if(o.type == 'base64') d = Base64_decode(d); - d = $cptable.utils.decode(1200, d.slice(2), 'str'); + d = typeof $cptable !== "undefined" ? $cptable.utils.decode(1200, d.slice(2), 'str') : utf16leread(d.slice(2)); o.type = "binary"; return read_plaintext(d, o); } @@ -67,6 +67,7 @@ function read_prn(data, d, o, str) { function readSync(data/*:RawData*/, opts/*:?ParseOpts*/)/*:Workbook*/ { reset_cp(); var o = opts||{}; + if(o.codepage && typeof $cptable === "undefined") console.error("Codepage tables are not loaded. Non-ASCII characters may not give expected results"); if(typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) return readSync(new Uint8Array(data), (o = dup(o), o.type = "array", o)); if(typeof Uint8Array !== 'undefined' && data instanceof Uint8Array && !o.type) o.type = typeof Deno !== "undefined" ? "buffer" : "array"; var d = data, n = [0,0,0,0], str = false;