Skip to content

Commit

Permalink
hodgepodge of fixes
Browse files Browse the repository at this point in the history
- missing formula elements rewritten to valid defined names (see SheetJS#680)
- comment author length limit enforced
- XLS ifmt references renamed to numFmtId for consistency with XLSB
- removed circular symlink
- mangle/compress with uglify
- more flow comments
  • Loading branch information
SheetJSDev committed Jul 27, 2017
1 parent 5ffa3e0 commit 6732eb7
Show file tree
Hide file tree
Showing 34 changed files with 256 additions and 194 deletions.
14 changes: 14 additions & 0 deletions .fossaignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
bits/
demos/
docbits/
misc/
node_modules/
types/
tests/
test_files

*.json
*.log
*.sh
.DS_Store
.Trashes
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
package-lock.json
*.tgz
_book/
misc/coverage.html
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ FLOWTARGET=$(LIB).flow.js
FLOWAUX=$(patsubst %.js,%.flow.js,$(AUXTARGETS))
AUXSCPTS=xlsxworker1.js xlsxworker2.js xlsxworker.js
FLOWTGTS=$(TARGET) $(AUXTARGETS) $(AUXSCPTS)
UGLIFYOPTS=--support-ie8
UGLIFYOPTS=--support-ie8 -c -m
CLOSURE=/usr/local/lib/node_modules/google-closure-compiler/compiler.jar

## Main Targets
Expand Down Expand Up @@ -54,11 +54,11 @@ init: ## Initial setup for development
dist: dist-deps $(TARGET) bower.json ## Prepare JS files for distribution
cp $(TARGET) dist/
cp LICENSE dist/
uglifyjs $(UGLIFYOPTS) $(TARGET) -o dist/$(LIB).min.js --source-map dist/$(LIB).min.map --preamble "$$(head -n 1 bits/00_header.js)"
uglifyjs $(TARGET) $(UGLIFYOPTS) -o dist/$(LIB).min.js --source-map dist/$(LIB).min.map --preamble "$$(head -n 1 bits/00_header.js)"
misc/strip_sourcemap.sh dist/$(LIB).min.js
uglifyjs $(UGLIFYOPTS) $(REQS) $(TARGET) -o dist/$(LIB).core.min.js --source-map dist/$(LIB).core.min.map --preamble "$$(head -n 1 bits/00_header.js)"
uglifyjs $(REQS) $(TARGET) $(UGLIFYOPTS) -o dist/$(LIB).core.min.js --source-map dist/$(LIB).core.min.map --preamble "$$(head -n 1 bits/00_header.js)"
misc/strip_sourcemap.sh dist/$(LIB).core.min.js
uglifyjs $(UGLIFYOPTS) $(REQS) $(ADDONS) $(TARGET) $(AUXTARGETS) -o dist/$(LIB).full.min.js --source-map dist/$(LIB).full.min.map --preamble "$$(head -n 1 bits/00_header.js)"
uglifyjs $(REQS) $(ADDONS) $(TARGET) $(AUXTARGETS) $(UGLIFYOPTS) -o dist/$(LIB).full.min.js --source-map dist/$(LIB).full.min.map --preamble "$$(head -n 1 bits/00_header.js)"
misc/strip_sourcemap.sh dist/$(LIB).full.min.js
cat <(head -n 1 bits/00_header.js) $(REQS) $(ADDONS) $(TARGET) $(AUXTARGETS) > demos/requirejs/$(LIB).full.js

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ enhancements, additional features by request, and dedicated support.

[**Commercial Support**](http://sheetjs.com/support)

[**Rendered Documentation**](https://sheetjs.gitbooks.io/docs/)
[**Rendered Documentation**](http://docs.sheetjs.com/)

[**In-Browser Demos**](http://sheetjs.com/demos)

Expand Down Expand Up @@ -41,6 +41,7 @@ enhancements, additional features by request, and dedicated support.
[![Build Status](https://travis-ci.org/SheetJS/js-xlsx.svg?branch=master)](https://travis-ci.org/SheetJS/js-xlsx)
[![Build Status](https://semaphoreci.com/api/v1/sheetjs/js-xlsx/branches/master/shields_badge.svg)](https://semaphoreci.com/sheetjs/js-xlsx)
[![Coverage Status](http://img.shields.io/coveralls/SheetJS/js-xlsx/master.svg)](https://coveralls.io/r/SheetJS/js-xlsx?branch=master)
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2FSheetJS%2Fjs-xlsx.svg?type=shield)](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2FSheetJS%2Fjs-xlsx?ref=badge_shield)
[![Dependencies Status](https://david-dm.org/sheetjs/js-xlsx/status.svg)](https://david-dm.org/sheetjs/js-xlsx)
[![NPM Downloads](https://img.shields.io/npm/dt/xlsx.svg)](https://npmjs.org/package/xlsx)
[![ghit.me](https://ghit.me/badge.svg?repo=sheetjs/js-xlsx)](https://ghit.me/repo/sheetjs/js-xlsx)
Expand Down
2 changes: 1 addition & 1 deletion bin/xlsx.njs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var wb_formats_2 = [
];
program.parse(process.argv);

var filename/*:?string*/, sheetname = '';
var filename = "", sheetname = '';
if(program.args[0]) {
filename = program.args[0];
if(program.args[1]) sheetname = program.args[1];
Expand Down
4 changes: 2 additions & 2 deletions bits/25_cellutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ function encode_cell_xls(c/*:CellAddress*/)/*:string*/ {

function encode_range_xls(r, opts)/*:string*/ {
if(r.s.r == 0 && !r.s.rRel) {
if(r.e.r == opts.biff >= 12 ? 0xFFFFF : 0xFFFF && !r.e.rRel) {
if(r.e.r == (opts.biff >= 12 ? 0xFFFFF : 0xFFFF) && !r.e.rRel) {
return (r.s.cRel ? "" : "$") + encode_col(r.s.c) + ":" + (r.e.cRel ? "" : "$") + encode_col(r.e.c);
}
}
if(r.s.c == 0 && !r.s.cRel) {
if(r.e.c == opts.biff >= 12 ? 0xFFFF : 0xFF && !r.e.cRel) {
if(r.e.c == (opts.biff >= 12 ? 0xFFFF : 0xFF) && !r.e.cRel) {
return (r.s.rRel ? "" : "$") + encode_row(r.s.r) + ":" + (r.e.rRel ? "" : "$") + encode_row(r.e.r);
}
}
Expand Down
6 changes: 3 additions & 3 deletions bits/27_csfutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ function safe_decode_range(range/*:string*/)/*:Range*/ {
function safe_format_cell(cell/*:Cell*/, v/*:any*/) {
var q = (cell.t == 'd' && v instanceof Date);
if(cell.z != null) try { return (cell.w = SSF.format(cell.z, q ? datenum(v) : v)); } catch(e) { }
try { return (cell.w = SSF.format((cell.XF||{}).ifmt||(q ? 14 : 0), q ? datenum(v) : v)); } catch(e) { return ''+v; }
try { return (cell.w = SSF.format((cell.XF||{}).numFmtId||(q ? 14 : 0), q ? datenum(v) : v)); } catch(e) { return ''+v; }
}

function format_cell(cell/*:Cell*/, v/*:any*/, o/*:any*/) {
if(cell == null || cell.t == null || cell.t == 'z') return "";
if(cell.w !== undefined) return cell.w;
if(cell.t == 'd' && !cell.z && o && o.dateNF) cell.z = o.dateNF;
if(v == undefined) return safe_format_cell(cell, cell.v, o);
return safe_format_cell(cell, v, o);
if(v == undefined) return safe_format_cell(cell, cell.v);
return safe_format_cell(cell, v);
}

function sheet_to_workbook(sheet/*:Worksheet*/, opts)/*:Workbook*/ {
Expand Down
4 changes: 2 additions & 2 deletions bits/28_binstructs.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ function parse_BrtColor(data, length/*:number*/) {
out.index = index;
var icv = XLSIcv[index];
/* automatic pseudo index 81 */
if(icv) out.rgb = icv[0].toString(16) + icv[1].toString(16) + icv[2].toString(16);
if(icv) out.rgb = rgb2Hex(icv);
break;
case 2:
/* if(!fValidRGB) throw new Error("invalid"); */
out.rgb = bR.toString(16) + bG.toString(16) + bB.toString(16);
out.rgb = rgb2Hex([bR, bG, bB]);
break;
case 3: out.theme = index; break;
}
Expand Down
14 changes: 9 additions & 5 deletions bits/30_ctype.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ var ct2type/*{[string]:string}*/ = ({
"application/vnd.openxmlformats-officedocument.spreadsheetml.connections+xml": "TODO",

/* External Links */
"application/vnd.ms-excel.externalLink": "TODO",
"application/vnd.openxmlformats-officedocument.spreadsheetml.externalLink+xml": "TODO",
"application/vnd.ms-excel.externalLink": "links",
"application/vnd.openxmlformats-officedocument.spreadsheetml.externalLink+xml": "links",

/* Metadata */
"application/vnd.ms-excel.sheetMetadata": "TODO",
Expand Down Expand Up @@ -188,13 +188,17 @@ var type2ct/*{[string]:Array<string>}*/ = evert_arr(ct2type);

XMLNS.CT = 'http://schemas.openxmlformats.org/package/2006/content-types';

function parse_ct(data/*:?string*/, opts) {
var ct = ({
function new_ct()/*:any*/ {
return ({
workbooks:[], sheets:[], charts:[], dialogs:[], macros:[],
rels:[], strs:[], comments:[],
rels:[], strs:[], comments:[], links:[],
coreprops:[], extprops:[], custprops:[], themes:[], styles:[],
calcchains:[], vba: [], drawings: [],
TODO:[], xmlns: "" }/*:any*/);
}

function parse_ct(data/*:?string*/, opts) {
var ct = new_ct();
if(!data || !data.match) return ct;
var ctext = {};
(data.match(tagregex)||[]).forEach(function(x) {
Expand Down
6 changes: 3 additions & 3 deletions bits/38_xlstypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function parse_FILETIME(blob) {
}

/* [MS-OSHARED] 2.3.3.1.4 Lpstr */
function parse_lpstr(blob, type, pad) {
function parse_lpstr(blob, type, pad/*:?number*/) {
var str = blob.read_shift(0, 'lpstr');
if(pad) blob.l += (4 - ((str.length+1) & 3)) & 3;
return str;
Expand All @@ -28,8 +28,8 @@ function parse_VtStringBase(blob, stringType, pad) {
return parse_lpstr(blob, stringType, pad);
}

function parse_VtString(blob, t, pad) { return parse_VtStringBase(blob, t, pad === false ? 0: 4); }
function parse_VtUnalignedString(blob, t) { if(!t) throw new Error("dafuq?"); return parse_VtStringBase(blob, t, 0); }
function parse_VtString(blob, t/*:number*/, pad/*:number*/) { return parse_VtStringBase(blob, t, pad === false ? 0: 4); }
function parse_VtUnalignedString(blob, t/*:number*/) { if(!t) throw new Error("dafuq?"); return parse_VtStringBase(blob, t, 0); }

/* [MS-OSHARED] 2.3.3.1.9 VtVecUnalignedLpstrValue */
function parse_VtVecUnalignedLpstrValue(blob) {
Expand Down
32 changes: 21 additions & 11 deletions bits/39_xlsbiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ function parse_OptXLUnicodeString(blob, length, opts) { return length === 0 ? ""
var parse_HideObjEnum = parseuint16;

/* 2.5.344 */
function parse_XTI(blob, length) {
var iSupBook = blob.read_shift(2), itabFirst = blob.read_shift(2,'i'), itabLast = blob.read_shift(2,'i');
function parse_XTI(blob, length, opts) {
var w = opts.biff > 8 ? 4 : 2;
var iSupBook = blob.read_shift(w), itabFirst = blob.read_shift(w,'i'), itabLast = blob.read_shift(w,'i');
return [iSupBook, itabFirst, itabLast];
}

Expand Down Expand Up @@ -195,10 +196,11 @@ function parse_BoundSheet8(blob, length, opts) {

/* 2.4.265 TODO */
function parse_SST(blob, length)/*:SST*/ {
var end = blob.l + length;
var cnt = blob.read_shift(4);
var ucnt = blob.read_shift(4);
var strs/*:SST*/ = ([]/*:any*/);
for(var i = 0; i != ucnt; ++i) {
for(var i = 0; i != ucnt && blob.l < end; ++i) {
strs.push(parse_XLUnicodeRichExtendedString(blob));
}
strs.Count = cnt; strs.Unique = ucnt;
Expand Down Expand Up @@ -308,9 +310,9 @@ function parse_Label(blob, length, opts) {

/* 2.4.126 Number Formats */
function parse_Format(blob, length, opts) {
var ifmt = blob.read_shift(2);
var numFmtId = blob.read_shift(2);
var fmtstr = parse_XLUnicodeString2(blob, 0, opts);
return [ifmt, fmtstr];
return [numFmtId, fmtstr];
}
var parse_BIFF2Format = parse_XLUnicodeString2;

Expand Down Expand Up @@ -401,7 +403,7 @@ function parse_StyleXF(blob, length, opts) {return parse_CellStyleXF(blob,length
/* 2.4.353 TODO: actually do this right */
function parse_XF(blob, length, opts) {
var o = {};
o.ifnt = blob.read_shift(2); o.ifmt = blob.read_shift(2); o.flags = blob.read_shift(2);
o.ifnt = blob.read_shift(2); o.numFmtId = blob.read_shift(2); o.flags = blob.read_shift(2);
o.fStyle = (o.flags >> 2) & 0x01;
length -= 6;
o.data = parse_CellStyleXF(blob, length, o.fStyle, opts);
Expand Down Expand Up @@ -447,7 +449,9 @@ function parse_SupBook(blob, length, opts) {
if(cch == 0x0401 || cch == 0x3A01) return [cch, ctab];
if(cch < 0x01 || cch >0xff) throw new Error("Unexpected SupBook type: "+cch);
var virtPath = parse_XLUnicodeStringNoCch(blob, cch);
var rgst = blob.read_shift(end - blob.l);
/* TODO: 2.5.277 Virtual Path */
var rgst = [];
while(end > blob.l) rgst.push(parse_XLUnicodeString(blob));
return [cch, ctab, virtPath, rgst];
}

Expand Down Expand Up @@ -512,15 +516,21 @@ function parse_Lbl(blob, length, opts) {
};
}

/* 2.4.106 TODO: verify supbook manipulation */
/* 2.4.106 TODO: verify filename encoding */
function parse_ExternSheet(blob, length, opts) {
if(opts.biff < 8) return parse_ShortXLUnicodeString(blob, length, opts);
var o = [], target = blob.l + length, len = blob.read_shift(2);
while(len-- !== 0) o.push(parse_XTI(blob, 6));
if(opts.biff < 8) return parse_BIFF5ExternSheet(blob, length, opts);
var o = [], target = blob.l + length, len = blob.read_shift(opts.biff > 8 ? 4 : 2);
while(len-- !== 0) o.push(parse_XTI(blob, opts.biff > 8 ? 12 : 6, opts));
// [iSupBook, itabFirst, itabLast];
var oo = [];
return o;
}
function parse_BIFF5ExternSheet(blob, length, opts) {
if(blob[blob.l + 1] == 0x03) blob[blob.l]++;
var o = parse_ShortXLUnicodeString(blob, length, opts);
return o.charCodeAt(0) == 0x03 ? o.slice(1) : o;
}
var parse_ExternCount = parseuint16;

/* 2.4.176 TODO: check older biff */
function parse_NameCmt(blob, length, opts) {
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions bits/48_stybin.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* [MS-XLSB] 2.4.651 BrtFmt */
function parse_BrtFmt(data, length/*:number*/) {
var ifmt = data.read_shift(2);
var numFmtId = data.read_shift(2);
var stFmtCode = parse_XLWideString(data,length-2);
return [ifmt, stFmtCode];
return [numFmtId, stFmtCode];
}
function write_BrtFmt(i/*:number*/, f/*:string*/, o) {
if(!o) o = new_buf(6 + 4 * f.length);
Expand Down Expand Up @@ -136,7 +136,7 @@ function parse_BrtXF(data, length/*:number*/) {
var ixfeParent = data.read_shift(2);
var ifmt = data.read_shift(2);
parsenoop(data, length-4);
return {ixfe:ixfeParent, ifmt:ifmt };
return {ixfe:ixfeParent, numFmtId:ifmt };
}
function write_BrtXF(data, ixfeP, o) {
if(!o) o = new_buf(16);
Expand Down
5 changes: 3 additions & 2 deletions bits/58_cmntbin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* [MS-XLSB] 2.4.28 BrtBeginComment */
function parse_BrtBeginComment(data, length) {
function parse_BrtBeginComment(data, length/*:number*/) {
var out = {};
out.iauthor = data.read_shift(4);
var rfx = parse_UncheckedRfX(data, 16);
Expand All @@ -21,6 +21,7 @@ function write_BrtBeginComment(data, o) {

/* [MS-XLSB] 2.4.324 BrtCommentAuthor */
var parse_BrtCommentAuthor = parse_XLWideString;
function write_BrtCommentAuthor(data) { return write_XLWideString(data.substr(0, 54)); }

/* [MS-XLSB] 2.1.7.8 Comments */
function parse_comments_bin(data, opts) {
Expand Down Expand Up @@ -72,7 +73,7 @@ function write_comments_bin(data, opts) {
comment[1].forEach(function(c) {
if(iauthor.indexOf(c.a) > -1) return;
iauthor.push(c.a.substr(0,54));
write_record(ba, "BrtCommentAuthor", write_XLWideString(c.a.substr(0, 54)));
write_record(ba, "BrtCommentAuthor", write_BrtCommentAuthor(c.a));
});
});
write_record(ba, "BrtEndCommentAuthors");
Expand Down
11 changes: 7 additions & 4 deletions bits/62_fxls.js
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,9 @@ var PtgBinOp = {
PtgPower: "^",
PtgSub: "-"
};
function get_ixti(supbooks, ixti/*:number*/, opts)/*:string*/ {
return supbooks.SheetNames[ixti];
}
function stringify_formula(formula/*Array<any>*/, range, cell/*:any*/, supbooks, opts) {
//console.log(formula);
var _range = /*range != null ? range :*/ {s:{c:0, r:0},e:{c:0, r:0}};
Expand Down Expand Up @@ -773,7 +776,7 @@ function stringify_formula(formula/*Array<any>*/, range, cell/*:any*/, supbooks,
break;
case 'PtgRef3d': /* 2.5.198.85 */
type = f[1][0]; ixti = /*::Number(*/f[1][1]/*::)*/; c = shift_cell_xls((f[1][2]/*:any*/), _range, opts);
sname = supbooks.SheetNames[ixti];
sname = get_ixti(supbooks, ixti, opts);
var w = sname; /* IE9 fails on defined names */
stack.push(sname + "!" + encode_cell_xls(c));
break;
Expand Down Expand Up @@ -825,7 +828,7 @@ function stringify_formula(formula/*Array<any>*/, range, cell/*:any*/, supbooks,
/* f[1] = type, 0, nameindex */
nameidx = (f[1][2]/*:any*/);
var lbl = (supbooks.names||[])[nameidx-1] || (supbooks[0]||[])[nameidx];
var name = lbl ? lbl.Name : "**MISSING**" + String(nameidx);
var name = lbl ? lbl.Name : "SH33TJSERR7" + String(nameidx);
if(name in XLSXFutureFunctions) name = XLSXFutureFunctions[name];
stack.push(name);
break;
Expand All @@ -850,11 +853,11 @@ function stringify_formula(formula/*Array<any>*/, range, cell/*:any*/, supbooks,
else o = supbooks.SheetNames[nameidx-1]+ "!";
if(supbooks[bookidx] && supbooks[bookidx][nameidx]) o += supbooks[bookidx][nameidx].Name;
else if(supbooks[0] && supbooks[0][nameidx]) o += supbooks[0][nameidx].Name;
else o += "??NAMEX??";
else o += "SH33TJSERRX";
stack.push(o);
break;
}
if(!externbook) externbook = {Name: "??NAMEX??"};
if(!externbook) externbook = {Name: "SH33TJSERRY"};
stack.push(externbook.Name);
break;

Expand Down
2 changes: 1 addition & 1 deletion bits/65_fods.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function csf_to_ods_formula(f/*:string*/)/*:string*/ {
return o.replace(/;/g, "|").replace(/,/g,";");
}

function ods_to_csf_range_3D(r/*:string*/) {
function ods_to_csf_range_3D(r/*:string*/)/*:[string, string]*/ {
var a = r.split(":");
var s = a[0].split(".")[0];
return [s, a[0].split(".")[1] + ":" + a[1].split(".")[1]];
Expand Down
10 changes: 5 additions & 5 deletions bits/66_wscommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function get_cell_style(styles, cell, opts) {
return len;
}

function safe_format(p, fmtid/*:number*/, fillid, opts, themes, styles) {
function safe_format(p, fmtid/*:number*/, fillid/*:number*/, opts, themes, styles) {
if(p.t === 'z') return;
if(p.t === 'd' && typeof p.v === 'string') p.v = parseDate(p.v);
try {
Expand All @@ -70,13 +70,13 @@ function safe_format(p, fmtid/*:number*/, fillid, opts, themes, styles) {
if(p.t === 'e') p.w = p.w || BErr[p.v];
else if(fmtid === 0) {
if(p.t === 'n') {
if((p.v|0) === p.v) p.w = SSF._general_int(p.v,_ssfopts);
else p.w = SSF._general_num(p.v,_ssfopts);
if((p.v|0) === p.v) p.w = SSF._general_int(p.v);
else p.w = SSF._general_num(p.v);
}
else if(p.t === 'd') {
var dd = datenum(p.v);
if((dd|0) === dd) p.w = SSF._general_int(dd,_ssfopts);
else p.w = SSF._general_num(dd,_ssfopts);
if((dd|0) === dd) p.w = SSF._general_int(dd);
else p.w = SSF._general_num(dd);
}
else if(p.v === undefined) return "";
else p.w = SSF._general(p.v,_ssfopts);
Expand Down
Loading

0 comments on commit 6732eb7

Please sign in to comment.