From e6b6f382c0acdc2fc297e54e749b05d6faa951f6 Mon Sep 17 00:00:00 2001 From: SheetJS Date: Mon, 18 Apr 2022 17:29:39 -0400 Subject: [PATCH] xsd:boolean strict truthy parsing (fixes #2658) Co-authored-by: Dmitry Kostochko --- bits/22_xmlutils.js | 8 +++++--- bits/67_wsxml.js | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/bits/22_xmlutils.js b/bits/22_xmlutils.js index 1e0504d..d873e88 100644 --- a/bits/22_xmlutils.js +++ b/bits/22_xmlutils.js @@ -82,12 +82,14 @@ var xlml_fixstr/*:StringConv*/ = /*#__PURE__*/(function() { })(); function xlml_unfixstr(str/*:string*/)/*:string*/ { return str.replace(/(\r\n|[\r\n])/g,"\ "); } +/* note: xsd:boolean valid values: true / 1 / false / 0 */ function parsexmlbool(value/*:any*/)/*:boolean*/ { switch(value) { - case 1: case true: case '1': case 'true': case 'TRUE': return true; - /* case '0': case 'false': case 'FALSE':*/ - default: return false; + case 1: case true: case '1': case 'true': return true; + case 0: case false: case '0': case 'false': return false; + //default: throw new Error("Invalid xsd:boolean " + value); } + return false; } function utf8reada(orig/*:string*/)/*:string*/ { diff --git a/bits/67_wsxml.js b/bits/67_wsxml.js index 6abac19..45ad1bd 100644 --- a/bits/67_wsxml.js +++ b/bits/67_wsxml.js @@ -246,7 +246,7 @@ function parse_ws_xml_sheetviews(data, wb/*:WBWBProps*/) { // $FlowIgnore if(+tag.zoomScale) wb.Views[i].zoom = +tag.zoomScale; // $FlowIgnore - if(parsexmlbool(tag.rightToLeft)) wb.Views[i].RTL = true; + if(tag.rightToLeft && parsexmlbool(tag.rightToLeft)) wb.Views[i].RTL = true; }); } function write_ws_xml_sheetviews(ws, opts, idx, wb)/*:string*/ { @@ -338,7 +338,7 @@ return function parse_ws_xml_data(sdata/*:string*/, s, opts, guess/*:Range*/, th if(opts.sheetRows && opts.sheetRows < tagr) continue; rowobj = {}; rowrite = false; if(tag.ht) { rowrite = true; rowobj.hpt = parseFloat(tag.ht); rowobj.hpx = pt2px(rowobj.hpt); } - if(tag.hidden == "1") { rowrite = true; rowobj.hidden = true; } + if(tag.hidden && parsexmlbool(tag.hidden)) { rowrite = true; rowobj.hidden = true; } if(tag.outlineLevel != null) { rowrite = true; rowobj.level = +tag.outlineLevel; } if(rowrite) rows[tagr-1] = rowobj; } @@ -355,7 +355,7 @@ return function parse_ws_xml_data(sdata/*:string*/, s, opts, guess/*:Range*/, th if(opts && opts.cellStyles) { rowobj = {}; rowrite = false; if(tag.ht) { rowrite = true; rowobj.hpt = parseFloat(tag.ht); rowobj.hpx = pt2px(rowobj.hpt); } - if(tag.hidden == "1") { rowrite = true; rowobj.hidden = true; } + if(tag.hidden && parsexmlbool(tag.hidden)) { rowrite = true; rowobj.hidden = true; } if(tag.outlineLevel != null) { rowrite = true; rowobj.level = +tag.outlineLevel; } if(rowrite) rows[tagr-1] = rowobj; }