From 04d5e49e951d2417d77b2a32b07cea51ed6bb04f Mon Sep 17 00:00:00 2001 From: SheetJS Date: Fri, 13 Apr 2018 00:48:21 -0400 Subject: [PATCH] version bump 0.12.9: XLSX/XLSB abnormal paths - support for arbitrary subfile paths in OPC - updated CFB to 1.0.6 --- bits/01_version.js | 2 +- bits/18_cfb.js | 13 +++++++------ bits/85_parsezip.js | 7 ++++++- dist/shim.min.js | 2 +- dist/xlsx.core.min.js | 28 ++++++++++++++-------------- dist/xlsx.core.min.map | 2 +- dist/xlsx.extendscript.js | 28 ++++++++++++++++++++-------- dist/xlsx.full.min.js | 32 ++++++++++++++++---------------- dist/xlsx.full.min.map | 2 +- dist/xlsx.js | 22 ++++++++++++++-------- dist/xlsx.min.js | 26 +++++++++++++------------- dist/xlsx.min.map | 2 +- package.json | 4 ++-- shim.js | 6 ++++++ test.js | 11 +++++++---- test_files | 2 +- tests/core.js | 11 +++++++---- tests/fixtures.js | 2 ++ tests/fixtures.lst | 2 ++ xlsx.flow.js | 22 ++++++++++++++-------- xlsx.js | 22 ++++++++++++++-------- 21 files changed, 150 insertions(+), 98 deletions(-) diff --git a/bits/01_version.js b/bits/01_version.js index 5c6db94..b27d6f8 100644 --- a/bits/01_version.js +++ b/bits/01_version.js @@ -1 +1 @@ -XLSX.version = '0.12.8'; +XLSX.version = '0.12.9'; diff --git a/bits/18_cfb.js b/bits/18_cfb.js index 7324ed9..b4db579 100644 --- a/bits/18_cfb.js +++ b/bits/18_cfb.js @@ -38,7 +38,7 @@ type CFBFiles = {[n:string]:CFBEntry}; /* [MS-CFB] v20171201 */ var CFB = (function _CFB(){ var exports/*:CFBModule*/ = /*::(*/{}/*:: :any)*/; -exports.version = '1.0.5'; +exports.version = '1.0.6'; /* [MS-CFB] 2.6.4 */ function namecmp(l/*:string*/, r/*:string*/)/*:number*/ { var L = l.split("/"), R = r.split("/"); @@ -216,8 +216,8 @@ function build_full_paths(FI/*:CFBFileIndex*/, FP/*:Array*/, Paths/*:Arr if(R !== -1 && dad[R] !== R) dad[i] = dad[R]; } if(C !== -1 /*NOSTREAM*/) dad[C] = i; - if(L !== -1) { dad[L] = dad[i]; q.push(L); } - if(R !== -1) { dad[R] = dad[i]; q.push(R); } + if(L !== -1) { dad[L] = dad[i]; if(q.lastIndexOf(L) < j) q.push(L); } + if(R !== -1) { dad[R] = dad[i]; if(q.lastIndexOf(R) < j) q.push(R); } } for(i=1; i < pl; ++i) if(dad[i] === i) { if(R !== -1 /*NOSTREAM*/ && dad[R] !== R) dad[i] = dad[R]; @@ -684,8 +684,9 @@ function cfb_new(opts/*:?any*/)/*:CFBContainer*/ { } function cfb_add(cfb/*:CFBContainer*/, name/*:string*/, content/*:?RawBytes*/, opts/*:?any*/)/*:CFBEntry*/ { - init_cfb(cfb); - var file = CFB.find(cfb, name); + var unsafe = opts && opts.unsafe; + if(!unsafe) init_cfb(cfb); + var file = !unsafe && CFB.find(cfb, name); if(!file) { var fpath/*:string*/ = cfb.FullPaths[0]; if(name.slice(0, fpath.length) == fpath) fpath = name; @@ -696,7 +697,7 @@ function cfb_add(cfb/*:CFBContainer*/, name/*:string*/, content/*:?RawBytes*/, o file = ({name: filename(name), type: 2}/*:any*/); cfb.FileIndex.push(file); cfb.FullPaths.push(fpath); - CFB.utils.cfb_gc(cfb); + if(!unsafe) CFB.utils.cfb_gc(cfb); } /*:: if(!file) throw new Error("unreachable"); */ file.content = (content/*:any*/); diff --git a/bits/85_parsezip.js b/bits/85_parsezip.js index b260d7c..ee877be 100644 --- a/bits/85_parsezip.js +++ b/bits/85_parsezip.js @@ -129,15 +129,20 @@ function parse_zip(zip/*:ZIP*/, opts/*:?ParseOpts*/)/*:Workbook*/ { } var wbext = xlsb ? "bin" : "xml"; - var wbrelsfile = 'xl/_rels/workbook.' + wbext + '.rels'; + var wbrelsi = dir.workbooks[0].lastIndexOf("/"); + var wbrelsfile = (dir.workbooks[0].slice(0, wbrelsi+1) + "_rels/" + dir.workbooks[0].slice(wbrelsi+1) + ".rels").replace(/^\//,""); + if(!safegetzipfile(zip, wbrelsfile)) wbrelsfile = 'xl/_rels/workbook.' + wbext + '.rels'; var wbrels = parse_rels(getzipstr(zip, wbrelsfile, true), wbrelsfile); if(wbrels) wbrels = safe_parse_wbrels(wbrels, wb.Sheets); + /* Numbers iOS hack */ var nmode = (getzipdata(zip,"xl/worksheets/sheet.xml",true))?1:0; for(i = 0; i != props.Worksheets; ++i) { var stype = "sheet"; if(wbrels && wbrels[i]) { path = 'xl/' + (wbrels[i][1]).replace(/[\/]?xl\//, ""); + if(!safegetzipfile(zip, path)) path = wbrels[i][1]; + if(!safegetzipfile(zip, path)) path = wbrelsfile.replace(/_rels\/.*$/,"") + wbrels[i][1]; stype = wbrels[i][2]; } else { path = 'xl/worksheets/sheet'+(i+1-nmode)+"." + wbext; diff --git a/dist/shim.min.js b/dist/shim.min.js index 4b72440..880a01b 100644 --- a/dist/shim.min.js +++ b/dist/shim.min.js @@ -1,2 +1,2 @@ /* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */ -if(!Object.keys)Object.keys=function(){var t=Object.prototype.hasOwnProperty,e=!{toString:null}.propertyIsEnumerable("toString"),r=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],i=r.length;return function(n){if(typeof n!=="object"&&typeof n!=="function"||n===null)throw new TypeError("Object.keys called on non-object");var o=[];for(var a in n)if(t.call(n,a))o.push(a);if(e)for(var l=0;l=0;--e)if(!t.charAt(e).match(/^\s/))return t.slice(0,e+1);return""};if(!Array.prototype.forEach)Array.prototype.forEach=function(t){var e=this.length>>>0,r=arguments[1]||void 0;for(var i=0;i>>0,r=arguments[1]||void 0,i=new Array(e);for(var n=0;n>>0,r=arguments[1]|0||0;for(r<0&&(r+=e)<0&&(r=0);r9999)r="+"+t(e,6);else if(e<0)r="-"+t(-e,6);else r=t(e,4);return[r,t(this.getUTCMonth()+1),t(this.getUTCDate())].join("-")+"T"+[t(this.getUTCHours()),t(this.getUTCMinutes()),t(this.getUTCSeconds())].join(":")+"."+t(this.getUTCMilliseconds(),3)+"Z"}}();if(typeof ArrayBuffer!=="undefined"&&!ArrayBuffer.prototype.slice)ArrayBuffer.prototype.slice=function(t,e){if(t==null)t=0;if(t<0){t+=this.byteLength;if(t<0)t=0}if(t>=this.byteLength)return new Uint8Array(0);if(e==null)e=this.byteLength;if(e<0){e+=this.byteLength;if(e<0)e=0}if(e>this.byteLength)e=this.byteLength;if(t>e)return new Uint8Array(0);var r=new ArrayBuffer(e-t);var i=new Uint8Array(r);var n=new Uint8Array(this,t,e-t);if(i.set)i.set(n);else while(t<=--e)i[e-t]=n[e];return r};if(typeof Uint8Array!=="undefined"&&!Uint8Array.prototype.slice)Uint8Array.prototype.slice=function(t,e){if(t==null)t=0;if(t<0){t+=this.length;if(t<0)t=0}if(t>=this.length)return new Uint8Array(0);if(e==null)e=this.length;if(e<0){e+=this.length;if(e<0)e=0}if(e>this.length)e=this.length;if(t>e)return new Uint8Array(0);var r=new Uint8Array(e-t);while(t<=--e)r[e-t]=this[e];return r};var IE_SaveFile=function(){try{if(typeof IE_SaveFile_Impl=="undefined")document.write(['