Skip to content

Commit 5c94936

Browse files
authored
Add quotes to worksheet references in formulae (#2046)
1 parent 5b08ba7 commit 5c94936

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

bits/62_fxls.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,9 +688,12 @@ var PtgBinOp = {
688688
PtgPower: "^",
689689
PtgSub: "-"
690690
};
691+
692+
// List of invalid characters needs to be tested further
693+
var quoteCharacters /*:RegExp */ = new RegExp(/[^\w\u4E00-\u9FFF\u3040-\u30FF]/)
691694
function formula_quote_sheet_name(sname/*:string*/, opts)/*:string*/ {
692695
if(!sname && !(opts && opts.biff <= 5 && opts.biff >= 2)) throw new Error("empty sheet name");
693-
if(sname.indexOf(" ") > -1) return "'" + sname + "'";
696+
if (quoteCharacters.test(sname)) return "'" + sname + "'";
694697
return sname;
695698
}
696699
function get_ixti_raw(supbooks, ixti/*:number*/, opts)/*:string*/ {

xlsx.flow.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11380,9 +11380,12 @@ var PtgBinOp = {
1138011380
PtgPower: "^",
1138111381
PtgSub: "-"
1138211382
};
11383+
11384+
// List of invalid characters needs to be tested further
11385+
var quoteCharacters /*:RegExp */ = new RegExp(/[^\w\u4E00-\u9FFF\u3040-\u30FF]/)
1138311386
function formula_quote_sheet_name(sname/*:string*/, opts)/*:string*/ {
1138411387
if(!sname && !(opts && opts.biff <= 5 && opts.biff >= 2)) throw new Error("empty sheet name");
11385-
if(sname.indexOf(" ") > -1) return "'" + sname + "'";
11388+
if (quoteCharacters.test(sname)) return "'" + sname + "'";
1138611389
return sname;
1138711390
}
1138811391
function get_ixti_raw(supbooks, ixti/*:number*/, opts)/*:string*/ {
@@ -20994,13 +20997,13 @@ function write_zip(wb/*:Workbook*/, opts/*:WriteOpts*/)/*:ZIP*/ {
2099420997
function firstbyte(f/*:RawData*/,o/*:?TypeOpts*/)/*:Array<number>*/ {
2099520998
var x = "";
2099620999
switch((o||{}).type || "base64") {
20997-
case 'buffer': return [f[0], f[1], f[2], f[3]];
20998-
case 'base64': x = Base64.decode(f.slice(0,24)); break;
21000+
case 'buffer': return [f[0], f[1], f[2], f[3], f[4], f[5], f[6], f[7]];
21001+
case 'base64': x = Base64.decode(f.slice(0,12)); break;
2099921002
case 'binary': x = f; break;
21000-
case 'array': return [f[0], f[1], f[2], f[3]];
21003+
case 'array': return [f[0], f[1], f[2], f[3], f[4], f[5], f[6], f[7]];
2100121004
default: throw new Error("Unrecognized type " + (o && o.type || "undefined"));
2100221005
}
21003-
return [x.charCodeAt(0), x.charCodeAt(1), x.charCodeAt(2), x.charCodeAt(3)];
21006+
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)];
2100421007
}
2100521008

2100621009
function read_cfb(cfb/*:CFBContainer*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
@@ -21075,7 +21078,7 @@ function readSync(data/*:RawData*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
2107521078
if(!vu.foo) {o=dup(o); o.type='array'; return readSync(ab2a(d), o);}
2107621079
}
2107721080
switch((n = firstbyte(d, o))[0]) {
21078-
case 0xD0: return read_cfb(CFB.read(d, o), o);
21081+
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;
2107921082
case 0x09: if(n[1] <= 0x04) return parse_xlscfb(d, o); break;
2108021083
case 0x3C: return parse_xlml(d, o);
2108121084
case 0x49: if(n[1] === 0x44) return read_wb_ID(d, o); break;

xlsx.js

Lines changed: 9 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)