Skip to content

Commit

Permalink
archaic browser compatibility and testing
Browse files Browse the repository at this point in the history
IE11 Compatibility View levels 5 and 7 (see SheetJS#952)
Firefox 5.0+ passes browser test (see SheetJS#950)
  • Loading branch information
reviewher committed Jan 11, 2018
1 parent 1d74977 commit c654a26
Show file tree
Hide file tree
Showing 28 changed files with 335 additions and 271 deletions.
8 changes: 4 additions & 4 deletions bits/02_codepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ function utf16beread(data/*:string*/)/*:string*/ {

var debom = function(data/*:string*/)/*:string*/ {
var c1 = data.charCodeAt(0), c2 = data.charCodeAt(1);
if(c1 == 0xFF && c2 == 0xFE) return utf16leread(data.substr(2));
if(c1 == 0xFE && c2 == 0xFF) return utf16beread(data.substr(2));
if(c1 == 0xFEFF) return data.substr(1);
if(c1 == 0xFF && c2 == 0xFE) return utf16leread(data.slice(2));
if(c1 == 0xFE && c2 == 0xFF) return utf16beread(data.slice(2));
if(c1 == 0xFEFF) return data.slice(1);
return data;
};

var _getchar = function _gc1(x/*:number*/)/*:string*/ { return String.fromCharCode(x); };
if(typeof cptable !== 'undefined') {
set_cp = function(cp/*:number*/) { current_codepage = cp; };
debom = function(data/*:string*/) {
if(data.charCodeAt(0) === 0xFF && data.charCodeAt(1) === 0xFE) { return cptable.utils.decode(1200, char_codes(data.substr(2))); }
if(data.charCodeAt(0) === 0xFF && data.charCodeAt(1) === 0xFE) { return cptable.utils.decode(1200, char_codes(data.slice(2))); }
return data;
};
_getchar = function _gc2(x/*:number*/)/*:string*/ {
Expand Down
9 changes: 9 additions & 0 deletions bits/05_buf.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ function arr2str(data/*:any*/)/*:string*/ {
var o/*:Array<string>*/ = []; for(var i = 0; i < data.length; ++i) o[i] = _chr(data[i]); return o.join("");
}

function ab2a(data/*:ArrayBuffer|Uint8Array*/)/*:Array<number>*/ {
if(typeof ArrayBuffer == 'undefined') throw new Error("Unsupported");
if(data instanceof ArrayBuffer) return ab2a(new Uint8Array(data));
/*:: if(data instanceof ArrayBuffer) throw new Error("unreachable"); */
var o = new Array(data.length);
for(var i = 0; i < data.length; ++i) o[i] = data[i];
return o;
}

var bconcat = function(bufs) { return [].concat.apply([], bufs); };

var chr0 = /\u0000/g, chr1 = /[\u0001-\u0006]/g;
5 changes: 3 additions & 2 deletions bits/20_jsutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ function parse_isodur(s) {
if(!m[i]) continue;
mt = 1;
if(i > 3) time = true;
switch(m[i].substr(m[i].length-1)) {
switch(m[i].slice(m[i].length-1)) {
case 'Y':
throw new Error("Unsupported ISO Duration Field: " + m[i].substr(m[i].length-1));
throw new Error("Unsupported ISO Duration Field: " + m[i].slice(m[i].length-1));
case 'D': mt *= 24;
/* falls through */
case 'H': mt *= 60;
Expand Down Expand Up @@ -100,6 +100,7 @@ function cc2str(arr/*:Array<number>*/)/*:string*/ {
function dup(o/*:any*/)/*:any*/ {
if(typeof JSON != 'undefined' && !Array.isArray(o)) return JSON.parse(JSON.stringify(o));
if(typeof o != 'object' || o == null) return o;
if(o instanceof Date) return new Date(o.getTime());
var out = {};
for(var k in o) if(o.hasOwnProperty(k)) out[k] = dup(o[k]);
return out;
Expand Down
12 changes: 6 additions & 6 deletions bits/22_xmlutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ function parsexmltag(tag/*:string*/, skip_root/*:?boolean*/)/*:any*/ {
var z = ({}/*:any*/);
var eq = 0, c = 0;
for(; eq !== tag.length; ++eq) if((c = tag.charCodeAt(eq)) === 32 || c === 10 || c === 13) break;
if(!skip_root) z[0] = tag.substr(0, eq);
if(!skip_root) z[0] = tag.slice(0, eq);
if(eq === tag.length) return z;
var m = tag.match(attregexg), j=0, v="", i=0, q="", cc="", quot = 1;
if(m) for(i = 0; i != m.length; ++i) {
cc = m[i];
for(c=0; c != cc.length; ++c) if(cc.charCodeAt(c) === 61) break;
q = cc.substr(0,c).trim();
q = cc.slice(0,c).trim();
while(cc.charCodeAt(c+1) == 32) ++c;
quot = ((eq=cc.charCodeAt(c+1)) == 34 || eq == 39) ? 1 : 0;
v = cc.substring(c+1+quot, cc.length-quot);
v = cc.slice(c+1+quot, cc.length-quot);
for(j=0;j!=q.length;++j) if(q.charCodeAt(j) === 58) break;
if(j===q.length) {
if(q.indexOf("_") > 0) q = q.substr(0, q.indexOf("_")); // from ods
if(q.indexOf("_") > 0) q = q.slice(0, q.indexOf("_")); // from ods
z[q] = v;
}
else {
var k = (j===5 && q.substr(0,5)==="xmlns"?"xmlns":"")+q.substr(j+1);
if(z[k] && q.substr(j-3,3) == "ext") continue; // from ods
var k = (j===5 && q.slice(0,5)==="xmlns"?"xmlns":"")+q.slice(j+1);
if(z[k] && q.slice(j-3,j) == "ext") continue; // from ods
z[k] = v;
}
}
Expand Down
6 changes: 3 additions & 3 deletions bits/28_binstructs.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ function write_BrtColor(color, o) {
o.write_shift(1, 0);
} else {
var rgb = (color.rgb || 'FFFFFF');
o.write_shift(1, parseInt(rgb.substr(0,2),16));
o.write_shift(1, parseInt(rgb.substr(2,2),16));
o.write_shift(1, parseInt(rgb.substr(4,2),16));
o.write_shift(1, parseInt(rgb.slice(0,2),16));
o.write_shift(1, parseInt(rgb.slice(2,4),16));
o.write_shift(1, parseInt(rgb.slice(4,6),16));
o.write_shift(1, 0xFF);
}
return o;
Expand Down
2 changes: 1 addition & 1 deletion bits/31_rels.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var RELS = ({
/* 9.3.3 Representing Relationships */
function get_rels_path(file/*:string*/)/*:string*/ {
var n = file.lastIndexOf("/");
return file.substr(0,n+1) + '_rels/' + file.substr(n+1) + ".rels";
return file.slice(0,n+1) + '_rels/' + file.slice(n+1) + ".rels";
}

function parse_rels(data/*:?string*/, currentFilePath/*:string*/) {
Expand Down
2 changes: 1 addition & 1 deletion bits/33_coreprops.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var CORE_PROPS_REGEX/*:Array<RegExp>*/ = (function() {
var r = new Array(CORE_PROPS.length);
for(var i = 0; i < CORE_PROPS.length; ++i) {
var f = CORE_PROPS[i];
var g = "(?:"+ f[0].substr(0,f[0].indexOf(":")) +":)"+ f[0].substr(f[0].indexOf(":")+1);
var g = "(?:"+ f[0].slice(0,f[0].indexOf(":")) +":)"+ f[0].slice(f[0].indexOf(":")+1);
r[i] = new RegExp("<" + g + "[^>]*>([\\s\\S]*?)<\/" + g + ">");
}
return r;
Expand Down
4 changes: 2 additions & 2 deletions bits/35_custprops.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function parse_cust_props(data/*:string*/, opts) {
case '</property>': name = null; break;
default: if (x.indexOf('<vt:') === 0) {
var toks = x.split('>');
var type = toks[0].substring(4), text = toks[1];
var type = toks[0].slice(4), text = toks[1];
/* 22.4.2.32 (CT_Variant). Omit the binary types from 22.4 (Variant Types) */
switch(type) {
case 'lpstr': case 'bstr': case 'lpwstr':
Expand All @@ -40,7 +40,7 @@ function parse_cust_props(data/*:string*/, opts) {
if(type.slice(-1) == '/') break;
if(opts.WTF && typeof console !== 'undefined') console.warn('Unexpected', x, type, toks);
}
} else if(x.substr(0,2) === "</") {/* empty */
} else if(x.slice(0,2) === "</") {/* empty */
} else if(opts.WTF) throw new Error(x);
}
}
Expand Down
5 changes: 3 additions & 2 deletions bits/38_xlstypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ function parse_ShortXLUnicodeString(blob, length, opts) {
} else if(opts.biff == 12) {
width = 2; encoding = 'wstr';
}
if(opts.biff >= 2 && opts.biff <= 5) encoding = 'cpstr';
var o = cch ? blob.read_shift(cch, encoding) : "";
current_codepage = cp;
return o;
Expand Down Expand Up @@ -342,7 +343,7 @@ function parse_XLUnicodeRichExtendedString(blob) {
function parse_XLUnicodeStringNoCch(blob, cch, opts) {
var retval;
if(opts) {
if(opts.biff >= 2 && opts.biff <= 5) return blob.read_shift(cch, 'sbcs-cont');
if(opts.biff >= 2 && opts.biff <= 5) return blob.read_shift(cch, 'cpstr');
if(opts.biff >= 12) return blob.read_shift(cch, 'dbcs-cont');
}
var fHighByte = blob.read_shift(1);
Expand All @@ -362,7 +363,7 @@ function parse_XLUnicodeString2(blob, length, opts) {
if(opts.biff > 5) return parse_XLUnicodeString(blob, length, opts);
var cch = blob.read_shift(1);
if(cch === 0) { blob.l++; return ""; }
return blob.read_shift(cch, opts.biff == 4 ? 'cpstr' : 'sbcs-cont');
return blob.read_shift(cch, (opts.biff <= 4 || !blob.lens ) ? 'cpstr' : 'sbcs-cont');
}
/* TODO: BIFF5 and lower, codepage awareness */
function write_XLUnicodeString(str, opts, o) {
Expand Down
38 changes: 19 additions & 19 deletions bits/40_harb.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function dbf_to_aoa(buf, opts)/*:AOA*/ {
out[R][C] = out[R][C].trim();
break;
case 'D':
if(s.length === 8) out[R][C] = new Date(+s.substr(0,4), +s.substr(4,2)-1, +s.substr(6,2));
if(s.length === 8) out[R][C] = new Date(+s.slice(0,4), +s.slice(4,6)-1, +s.slice(6,8));
else out[R][C] = s;
break;
case 'F': out[R][C] = parseFloat(s.trim()); break;
Expand Down Expand Up @@ -325,18 +325,18 @@ var SYLK = (function() {
case 'O': break; /* options? */
case 'P':
if(record[1].charAt(0) == 'P')
formats.push(rstr.substr(3).replace(/;;/g, ";"));
formats.push(rstr.slice(3).replace(/;;/g, ";"));
break;
case 'C':
for(rj=1; rj<record.length; ++rj) switch(record[rj].charAt(0)) {
case 'X': C = parseInt(record[rj].substr(1))-1; break;
case 'X': C = parseInt(record[rj].slice(1))-1; break;
case 'Y':
R = parseInt(record[rj].substr(1))-1; C = 0;
R = parseInt(record[rj].slice(1))-1; C = 0;
for(j = arr.length; j <= R; ++j) arr[j] = [];
break;
case 'K':
val = record[rj].substr(1);
if(val.charAt(0) === '"') val = val.substr(1,val.length - 2);
val = record[rj].slice(1);
if(val.charAt(0) === '"') val = val.slice(1,val.length - 1);
else if(val === 'TRUE') val = true;
else if(val === 'FALSE') val = false;
else if(!isNaN(fuzzynum(val))) {
Expand All @@ -349,39 +349,39 @@ var SYLK = (function() {
next_cell_format = null;
break;
case 'E':
var formula = rc_to_a1(record[rj].substr(1), {r:R,c:C});
var formula = rc_to_a1(record[rj].slice(1), {r:R,c:C});
arr[R][C] = [arr[R][C], formula];
break;
default: if(opts && opts.WTF) throw new Error("SYLK bad record " + rstr);
} break;
case 'F':
var F_seen = 0;
for(rj=1; rj<record.length; ++rj) switch(record[rj].charAt(0)) {
case 'X': C = parseInt(record[rj].substr(1))-1; ++F_seen; break;
case 'X': C = parseInt(record[rj].slice(1))-1; ++F_seen; break;
case 'Y':
R = parseInt(record[rj].substr(1))-1; /*C = 0;*/
R = parseInt(record[rj].slice(1))-1; /*C = 0;*/
for(j = arr.length; j <= R; ++j) arr[j] = [];
break;
case 'M': Mval = parseInt(record[rj].substr(1)) / 20; break;
case 'M': Mval = parseInt(record[rj].slice(1)) / 20; break;
case 'F': break; /* ??? */
case 'P':
next_cell_format = formats[parseInt(record[rj].substr(1))];
next_cell_format = formats[parseInt(record[rj].slice(1))];
break;
case 'S': break; /* cell style */
case 'D': break; /* column */
case 'N': break; /* font */
case 'W':
cw = record[rj].substr(1).split(" ");
cw = record[rj].slice(1).split(" ");
for(j = parseInt(cw[0], 10); j <= parseInt(cw[1], 10); ++j) {
Mval = parseInt(cw[2], 10);
colinfo[j-1] = Mval === 0 ? {hidden:true}: {wch:Mval}; process_col(colinfo[j-1]);
} break;
case 'C': /* default column format */
C = parseInt(record[rj].substr(1))-1;
C = parseInt(record[rj].slice(1))-1;
if(!colinfo[C]) colinfo[C] = {};
break;
case 'R': /* row properties */
R = parseInt(record[rj].substr(1))-1;
R = parseInt(record[rj].slice(1))-1;
if(!rowinfo[R]) rowinfo[R] = {};
if(Mval > 0) { rowinfo[R].hpt = Mval; rowinfo[R].hpx = pt2px(Mval); }
else if(Mval === 0) rowinfo[R].hidden = true;
Expand Down Expand Up @@ -506,7 +506,7 @@ var DIF = (function() {
else arr[R][C] = value;
++C; break;
case 1:
data = data.substr(1,data.length-2);
data = data.slice(1,data.length-1);
arr[R][C++] = data !== '' ? data : null;
break;
}
Expand Down Expand Up @@ -761,8 +761,8 @@ var PRN = (function() {
var ws/*:Worksheet*/ = o.dense ? ([]/*:any*/) : ({}/*:any*/);
var range/*:Range*/ = ({s: {c:0, r:0}, e: {c:0, r:0}}/*:any*/);

if(str.substr(0,4) == "sep=" && str.charCodeAt(5) == 10) { sep = str.charAt(4); str = str.substr(6); }
else sep = guess_sep(str.substr(0,1024));
if(str.slice(0,4) == "sep=" && str.charCodeAt(5) == 10) { sep = str.charAt(4); str = str.slice(6); }
else sep = guess_sep(str.slice(0,1024));
var R = 0, C = 0, v = 0;
var start = 0, end = 0, sepcc = sep.charCodeAt(0), instr = false, cc=0;
str = str.replace(/\r\n/mg, "\n");
Expand All @@ -776,7 +776,7 @@ var PRN = (function() {
else if(s.trim().length === 0) { cell.t = 's'; cell.v = s; }
else if(s.charCodeAt(0) == 0x3D) {
if(s.charCodeAt(1) == 0x22 && s.charCodeAt(s.length - 1) == 0x22) { cell.t = 's'; cell.v = s.slice(2,-1).replace(/""/g,'"'); }
else if(fuzzyfmla(s)) { cell.t = 'n'; cell.f = s.substr(1); }
else if(fuzzyfmla(s)) { cell.t = 'n'; cell.f = s.slice(1); }
else { cell.t = 's'; cell.v = s; } }
else if(s == "TRUE") { cell.t = 'b'; cell.v = true; }
else if(s == "FALSE") { cell.t = 'b'; cell.v = false; }
Expand Down Expand Up @@ -846,7 +846,7 @@ var PRN = (function() {
var coord = encode_cell({r:R,c:C});
cell = dense ? (ws[R]||[])[C] : ws[coord];
if(!cell || cell.v == null) { oo.push(" "); continue; }
var w = (cell.w || (format_cell(cell), cell.w) || "").substr(0,10);
var w = (cell.w || (format_cell(cell), cell.w) || "").slice(0,10);
while(w.length < 10) w += " ";
oo.push(w + (C === 0 ? " " : ""));
}
Expand Down
4 changes: 2 additions & 2 deletions bits/41_lotus.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var WK_ = (function() {
break;
case 0x06: refguess = val; break; /* RANGE */
case 0x0F: /* LABEL */
if(!o.qpro) val[1].v = val[1].v.substr(1);
if(!o.qpro) val[1].v = val[1].v.slice(1);
/* falls through */
case 0x0D: /* INTEGER */
case 0x0E: /* NUMBER */
Expand All @@ -63,7 +63,7 @@ var WK_ = (function() {
break;
} else switch(RT) {
case 0x16: /* LABEL16 */
val[1].v = val[1].v.substr(1);
val[1].v = val[1].v.slice(1);
/* falls through */
case 0x17: /* NUMBER17 */
case 0x18: /* NUMBER18 */
Expand Down
2 changes: 1 addition & 1 deletion bits/42_sstxml.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ var parse_rs = (function parse_rs_factory() {

/* 18.3.1.15 color CT_Color TODO: tint, theme, auto, indexed */
case '<color':
if(y.rgb) font.color = y.rgb.substr(2,6);
if(y.rgb) font.color = y.rgb.slice(2,8);
break;

/* 18.8.18 family ST_FontFamily */
Expand Down
6 changes: 3 additions & 3 deletions bits/46_stycommon.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
function hex2RGB(h) {
var o = h.substr(h[0]==="#"?1:0,6);
return [parseInt(o.substr(0,2),16),parseInt(o.substr(2,2),16),parseInt(o.substr(4,2),16)];
var o = h.slice(h[0]==="#"?1:0).slice(0,6);
return [parseInt(o.slice(0,2),16),parseInt(o.slice(2,4),16),parseInt(o.slice(4,6),16)];
}
function rgb2Hex(rgb) {
for(var i=0,o=1; i!=3; ++i) o = o*256 + (rgb[i]>255?255:rgb[i]<0?0:rgb[i]);
return o.toString(16).toUpperCase().substr(1);
return o.toString(16).toUpperCase().slice(1);
}

function rgb2HSL(rgb) {
Expand Down
2 changes: 1 addition & 1 deletion bits/49_theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function parse_clrScheme(t, themes, opts) {
themes.themeElements.clrScheme.push(color);
color = {};
} else {
color.name = y[0].substring(3, y[0].length - 1);
color.name = y[0].slice(3, y[0].length - 1);
}
break;

Expand Down
6 changes: 3 additions & 3 deletions bits/62_fxls.js
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,8 @@ var PtgBinOp = {
PtgPower: "^",
PtgSub: "-"
};
function formula_quote_sheet_name(sname/*:string*/)/*:string*/ {
if(!sname) throw new Error("empty sheet name");
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 + "'";
return sname;
}
Expand Down Expand Up @@ -730,7 +730,7 @@ function get_ixti_raw(supbooks, ixti/*:number*/, opts)/*:string*/ {
}
}
function get_ixti(supbooks, ixti/*:number*/, opts)/*:string*/ {
return formula_quote_sheet_name(get_ixti_raw(supbooks, ixti, opts));
return formula_quote_sheet_name(get_ixti_raw(supbooks, ixti, opts), opts);
}
function stringify_formula(formula/*Array<any>*/, range, cell/*:any*/, supbooks, opts)/*:string*/ {
var _range = /*range != null ? range :*/ {s:{c:0, r:0},e:{c:0, r:0}};
Expand Down
6 changes: 3 additions & 3 deletions bits/65_fods.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* Part 3 TODO: actually parse formulae */
function ods_to_csf_formula(f/*:string*/)/*:string*/ {
if(f.substr(0,3) == "of:") f = f.substr(3);
if(f.slice(0,3) == "of:") f = f.slice(3);
/* 5.2 Basic Expressions */
if(f.charCodeAt(0) == 61) {
f = f.substr(1);
if(f.charCodeAt(0) == 61) f = f.substr(1);
f = f.slice(1);
if(f.charCodeAt(0) == 61) f = f.slice(1);
}
f = f.replace(/COM\.MICROSOFT\./g, "");
/* Part 3 Section 5.8 References */
Expand Down
Loading

0 comments on commit c654a26

Please sign in to comment.