From 5c94936cfd4e50e3842d0731f2d0d534d015f23a Mon Sep 17 00:00:00 2001 From: Mohammed Sahl <32067562+mohammedsahl@users.noreply.github.com> Date: Fri, 3 Jul 2020 19:46:07 -0400 Subject: [PATCH] Add quotes to worksheet references in formulae (#2046) --- bits/62_fxls.js | 5 ++++- xlsx.flow.js | 15 +++++++++------ xlsx.js | 15 +++++++++------ 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/bits/62_fxls.js b/bits/62_fxls.js index 98d3a5e..8bf9812 100644 --- a/bits/62_fxls.js +++ b/bits/62_fxls.js @@ -688,9 +688,12 @@ var PtgBinOp = { PtgPower: "^", PtgSub: "-" }; + +// List of invalid characters needs to be tested further +var quoteCharacters /*:RegExp */ = new RegExp(/[^\w\u4E00-\u9FFF\u3040-\u30FF]/) function formula_quote_sheet_name(sname/*:string*/, opts)/*:string*/ { if(!sname && !(opts && opts.biff <= 5 && opts.biff >= 2)) throw new Error("empty sheet name"); - if(sname.indexOf(" ") > -1) return "'" + sname + "'"; + if (quoteCharacters.test(sname)) return "'" + sname + "'"; return sname; } function get_ixti_raw(supbooks, ixti/*:number*/, opts)/*:string*/ { diff --git a/xlsx.flow.js b/xlsx.flow.js index 69efe85..feb52db 100644 --- a/xlsx.flow.js +++ b/xlsx.flow.js @@ -11380,9 +11380,12 @@ var PtgBinOp = { PtgPower: "^", PtgSub: "-" }; + +// List of invalid characters needs to be tested further +var quoteCharacters /*:RegExp */ = new RegExp(/[^\w\u4E00-\u9FFF\u3040-\u30FF]/) function formula_quote_sheet_name(sname/*:string*/, opts)/*:string*/ { if(!sname && !(opts && opts.biff <= 5 && opts.biff >= 2)) throw new Error("empty sheet name"); - if(sname.indexOf(" ") > -1) return "'" + sname + "'"; + if (quoteCharacters.test(sname)) return "'" + sname + "'"; return sname; } function get_ixti_raw(supbooks, ixti/*:number*/, opts)/*:string*/ { @@ -20994,13 +20997,13 @@ function write_zip(wb/*:Workbook*/, opts/*:WriteOpts*/)/*:ZIP*/ { function firstbyte(f/*:RawData*/,o/*:?TypeOpts*/)/*:Array*/ { var x = ""; switch((o||{}).type || "base64") { - case 'buffer': return [f[0], f[1], f[2], f[3]]; - case 'base64': x = Base64.decode(f.slice(0,24)); break; + case 'buffer': return [f[0], f[1], f[2], f[3], f[4], f[5], f[6], f[7]]; + case 'base64': x = Base64.decode(f.slice(0,12)); break; case 'binary': x = f; break; - case 'array': return [f[0], f[1], f[2], f[3]]; + case 'array': return [f[0], f[1], f[2], f[3], f[4], f[5], f[6], f[7]]; default: throw new Error("Unrecognized type " + (o && o.type || "undefined")); } - return [x.charCodeAt(0), x.charCodeAt(1), x.charCodeAt(2), x.charCodeAt(3)]; + return [x.charCodeAt(0), x.charCodeAt(1), x.charCodeAt(2), x.charCodeAt(3), x.charCodeAt(4), x.charCodeAt(5), x.charCodeAt(6), x.charCodeAt(7)]; } function read_cfb(cfb/*:CFBContainer*/, opts/*:?ParseOpts*/)/*:Workbook*/ { @@ -21075,7 +21078,7 @@ function readSync(data/*:RawData*/, opts/*:?ParseOpts*/)/*:Workbook*/ { if(!vu.foo) {o=dup(o); o.type='array'; return readSync(ab2a(d), o);} } switch((n = firstbyte(d, o))[0]) { - case 0xD0: return read_cfb(CFB.read(d, o), o); + case 0xD0: if(n[1] === 0xCF && n[2] === 0x11 && n[3] === 0xE0 && n[4] === 0xA1 && n[5] === 0xB1 && n[6] === 0x1A && n[7] === 0xE1) return read_cfb(CFB.read(d, o), o); break; case 0x09: if(n[1] <= 0x04) return parse_xlscfb(d, o); break; case 0x3C: return parse_xlml(d, o); case 0x49: if(n[1] === 0x44) return read_wb_ID(d, o); break; diff --git a/xlsx.js b/xlsx.js index 253c708..92ff6e0 100644 --- a/xlsx.js +++ b/xlsx.js @@ -11278,9 +11278,12 @@ var PtgBinOp = { PtgPower: "^", PtgSub: "-" }; + +// List of invalid characters needs to be tested further +var quoteCharacters = new RegExp(/[^\w\u4E00-\u9FFF\u3040-\u30FF]/) function formula_quote_sheet_name(sname, opts) { if(!sname && !(opts && opts.biff <= 5 && opts.biff >= 2)) throw new Error("empty sheet name"); - if(sname.indexOf(" ") > -1) return "'" + sname + "'"; + if (quoteCharacters.test(sname)) return "'" + sname + "'"; return sname; } function get_ixti_raw(supbooks, ixti, opts) { @@ -20871,13 +20874,13 @@ f = "docProps/app.xml"; function firstbyte(f,o) { var x = ""; switch((o||{}).type || "base64") { - case 'buffer': return [f[0], f[1], f[2], f[3]]; - case 'base64': x = Base64.decode(f.slice(0,24)); break; + case 'buffer': return [f[0], f[1], f[2], f[3], f[4], f[5], f[6], f[7]]; + case 'base64': x = Base64.decode(f.slice(0,12)); break; case 'binary': x = f; break; - case 'array': return [f[0], f[1], f[2], f[3]]; + case 'array': return [f[0], f[1], f[2], f[3], f[4], f[5], f[6], f[7]]; default: throw new Error("Unrecognized type " + (o && o.type || "undefined")); } - return [x.charCodeAt(0), x.charCodeAt(1), x.charCodeAt(2), x.charCodeAt(3)]; + return [x.charCodeAt(0), x.charCodeAt(1), x.charCodeAt(2), x.charCodeAt(3), x.charCodeAt(4), x.charCodeAt(5), x.charCodeAt(6), x.charCodeAt(7)]; } function read_cfb(cfb, opts) { @@ -20951,7 +20954,7 @@ function readSync(data, opts) { if(!vu.foo) {o=dup(o); o.type='array'; return readSync(ab2a(d), o);} } switch((n = firstbyte(d, o))[0]) { - case 0xD0: return read_cfb(CFB.read(d, o), o); + case 0xD0: if(n[1] === 0xCF && n[2] === 0x11 && n[3] === 0xE0 && n[4] === 0xA1 && n[5] === 0xB1 && n[6] === 0x1A && n[7] === 0xE1) return read_cfb(CFB.read(d, o), o); break; case 0x09: if(n[1] <= 0x04) return parse_xlscfb(d, o); break; case 0x3C: return parse_xlml(d, o); case 0x49: if(n[1] === 0x44) return read_wb_ID(d, o); break;