Skip to content

Commit d882757

Browse files
committed
enforcing 31 character sheet name restriction
1 parent f634261 commit d882757

13 files changed

+64
-49
lines changed

bits/36_xmlutils.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ var rencstr = "&<>'\"".split("");
2828
function unescapexml(text){
2929
var s = text + '';
3030
s = s.replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&amp;/g, "&");
31-
//for(var y in encodings) s = s.replace(new RegExp(y,'g'), encodings[y]);
3231
return s.replace(/_x([0-9a-fA-F]*)_/g,function(m,c) {return _chr(parseInt(c,16));});
3332
}
3433
function escapexml(text){

bits/72_wsxml.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,37 @@ function parse_ws_xml(data, opts, rels) {
1818
}
1919

2020
var refguess = {s: {r:1000000, c:1000000}, e: {r:0, c:0} };
21-
var q = (opts.cellFormula ? ["v","f"] : ["v"]);
2221
var sidx = 0;
2322

23+
var match_v = matchtag("v"), match_f = matchtag("f");
2424
/* 18.3.1.80 sheetData CT_SheetData ? */
25-
if((mtch=data.match(/<(?:\w+:)?sheetData>([^\u2603]*)<\/(?:\w+:)?sheetData>/m))) mtch[1].split(/<\/(?:\w+:)?row>/).forEach(function(x) {
26-
if(x === "" || x.trim() === "") return;
25+
mtch=data.match(/<(?:\w+:)?sheetData>([^\u2603]*)<\/(?:\w+:)?sheetData>/m);
26+
if(mtch) for(var marr = mtch[1].split(/<\/(?:\w+:)?row>/), mt = 0; mt != marr.length; ++mt) {
27+
x = marr[mt];
28+
if(x === "" || x.trim() === "") continue;
2729

2830
/* 18.3.1.73 row CT_Row */
2931
var row = parsexmltag(x.match(/<(?:\w+:)?row[^>]*>/)[0]);
30-
if(opts.sheetRows && opts.sheetRows < +row.r) return;
32+
if(opts.sheetRows && opts.sheetRows < +row.r) continue;
3133
if(refguess.s.r > row.r - 1) refguess.s.r = row.r - 1;
3234
if(refguess.e.r < row.r - 1) refguess.e.r = row.r - 1;
3335
/* 18.3.1.4 c CT_Cell */
3436
var cells = x.substr(x.indexOf('>')+1).split(/<(?:\w+:)?c /);
35-
cells.forEach(function(c, idx) { if(c === "" || c.trim() === "") return;
36-
var cref = c.match(/r=["']([^"']*)["']/);
37+
for(var ix = 0, c=cells[0]; ix != cells.length; ++ix,c=cells[ix]) {
38+
if(c === "" || c.trim() === "") continue;
39+
var cref = c.match(/r=["']([^"']*)["']/), idx = ix;
3740
c = "<c " + c;
3841
if(cref && cref.length == 2) idx = decode_cell(cref[1]).c;
3942
var cell = parsexmltag((c.match(/<c[^>]*>/)||[c])[0]); delete cell[0];
4043
var d = c.substr(c.indexOf('>')+1);
4144
var p = {};
42-
q.forEach(function(f){var x=d.match(matchtag(f));if(x)p[f]=unescapexml(x[1]);});
45+
46+
var x=d.match(match_v);if(x)p.v=unescapexml(x[1]);
47+
if(opts.cellFormula) {x=d.match(match_f);if(x)p.f=unescapexml(x[1]);}
48+
4349
/* SCHEMA IS ACTUALLY INCORRECT HERE. IF A CELL HAS NO T, EMIT "" */
4450
if(cell.t === undefined && p.v === undefined) {
45-
if(!opts.sheetStubs) return;
51+
if(!opts.sheetStubs) continue;
4652
p.t = "str"; p.v = undefined;
4753
}
4854
else p.t = (cell.t ? cell.t : "n"); // default is "n" in schema
@@ -93,8 +99,8 @@ function parse_ws_xml(data, opts, rels) {
9399
}
94100
} catch(e) { if(opts.WTF) throw e; }
95101
s[cell.r] = p;
96-
});
97-
});
102+
};
103+
}
98104

99105
/* 18.3.1.48 hyperlinks CT_Hyperlinks */
100106
if(data.match(/<\/hyperlinks>/)) data.match(/<hyperlink[^>]*\/>/g).forEach(function(h) {

bits/77_wbxml.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ var write_wb_xml = function(wb, opts) {
136136
o.push("<sheets>");
137137
var i = 1;
138138
wb.SheetNames.forEach(function(s) {
139-
o.push(writextag('sheet',null,{name:s, sheetId:String(i), "r:id":"rId"+i}));
139+
o.push(writextag('sheet',null,{name:s.substr(0,31), sheetId:String(i), "r:id":"rId"+i}));
140140
++i;
141141
});
142142
o.push("</sheets>");

bits/78_wbbin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var write_BrtBundleSh = function(data, o) {
1212
o.write_shift(4, data.hsState);
1313
o.write_shift(4, data.iTabID);
1414
write_RelID(data.strRelID, o);
15-
write_XLWideString(data.name, o);
15+
write_XLWideString(data.name.substr(0,31), o);
1616
return o;
1717
};
1818

dist/xlsx.core.min.js

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

dist/xlsx.core.min.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/xlsx.full.min.js

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

dist/xlsx.full.min.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/xlsx.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,6 @@ var rencstr = "&<>'\"".split("");
677677
function unescapexml(text){
678678
var s = text + '';
679679
s = s.replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&amp;/g, "&");
680-
//for(var y in encodings) s = s.replace(new RegExp(y,'g'), encodings[y]);
681680
return s.replace(/_x([0-9a-fA-F]*)_/g,function(m,c) {return _chr(parseInt(c,16));});
682681
}
683682
function escapexml(text){
@@ -2506,31 +2505,37 @@ function parse_ws_xml(data, opts, rels) {
25062505
}
25072506

25082507
var refguess = {s: {r:1000000, c:1000000}, e: {r:0, c:0} };
2509-
var q = (opts.cellFormula ? ["v","f"] : ["v"]);
25102508
var sidx = 0;
25112509

2510+
var match_v = matchtag("v"), match_f = matchtag("f");
25122511
/* 18.3.1.80 sheetData CT_SheetData ? */
2513-
if((mtch=data.match(/<(?:\w+:)?sheetData>([^\u2603]*)<\/(?:\w+:)?sheetData>/m))) mtch[1].split(/<\/(?:\w+:)?row>/).forEach(function(x) {
2514-
if(x === "" || x.trim() === "") return;
2512+
mtch=data.match(/<(?:\w+:)?sheetData>([^\u2603]*)<\/(?:\w+:)?sheetData>/m);
2513+
if(mtch) for(var marr = mtch[1].split(/<\/(?:\w+:)?row>/), mt = 0; mt != marr.length; ++mt) {
2514+
x = marr[mt];
2515+
if(x === "" || x.trim() === "") continue;
25152516

25162517
/* 18.3.1.73 row CT_Row */
25172518
var row = parsexmltag(x.match(/<(?:\w+:)?row[^>]*>/)[0]);
2518-
if(opts.sheetRows && opts.sheetRows < +row.r) return;
2519+
if(opts.sheetRows && opts.sheetRows < +row.r) continue;
25192520
if(refguess.s.r > row.r - 1) refguess.s.r = row.r - 1;
25202521
if(refguess.e.r < row.r - 1) refguess.e.r = row.r - 1;
25212522
/* 18.3.1.4 c CT_Cell */
25222523
var cells = x.substr(x.indexOf('>')+1).split(/<(?:\w+:)?c /);
2523-
cells.forEach(function(c, idx) { if(c === "" || c.trim() === "") return;
2524-
var cref = c.match(/r=["']([^"']*)["']/);
2524+
for(var ix = 0, c=cells[0]; ix != cells.length; ++ix,c=cells[ix]) {
2525+
if(c === "" || c.trim() === "") continue;
2526+
var cref = c.match(/r=["']([^"']*)["']/), idx = ix;
25252527
c = "<c " + c;
25262528
if(cref && cref.length == 2) idx = decode_cell(cref[1]).c;
25272529
var cell = parsexmltag((c.match(/<c[^>]*>/)||[c])[0]); delete cell[0];
25282530
var d = c.substr(c.indexOf('>')+1);
25292531
var p = {};
2530-
q.forEach(function(f){var x=d.match(matchtag(f));if(x)p[f]=unescapexml(x[1]);});
2532+
2533+
var x=d.match(match_v);if(x)p.v=unescapexml(x[1]);
2534+
if(opts.cellFormula) {x=d.match(match_f);if(x)p.f=unescapexml(x[1]);}
2535+
25312536
/* SCHEMA IS ACTUALLY INCORRECT HERE. IF A CELL HAS NO T, EMIT "" */
25322537
if(cell.t === undefined && p.v === undefined) {
2533-
if(!opts.sheetStubs) return;
2538+
if(!opts.sheetStubs) continue;
25342539
p.t = "str"; p.v = undefined;
25352540
}
25362541
else p.t = (cell.t ? cell.t : "n"); // default is "n" in schema
@@ -2581,8 +2586,8 @@ function parse_ws_xml(data, opts, rels) {
25812586
}
25822587
} catch(e) { if(opts.WTF) throw e; }
25832588
s[cell.r] = p;
2584-
});
2585-
});
2589+
};
2590+
}
25862591

25872592
/* 18.3.1.48 hyperlinks CT_Hyperlinks */
25882593
if(data.match(/<\/hyperlinks>/)) data.match(/<hyperlink[^>]*\/>/g).forEach(function(h) {
@@ -3283,7 +3288,7 @@ var write_wb_xml = function(wb, opts) {
32833288
o.push("<sheets>");
32843289
var i = 1;
32853290
wb.SheetNames.forEach(function(s) {
3286-
o.push(writextag('sheet',null,{name:s, sheetId:String(i), "r:id":"rId"+i}));
3291+
o.push(writextag('sheet',null,{name:s.substr(0,31), sheetId:String(i), "r:id":"rId"+i}));
32873292
++i;
32883293
});
32893294
o.push("</sheets>");
@@ -3304,7 +3309,7 @@ var write_BrtBundleSh = function(data, o) {
33043309
o.write_shift(4, data.hsState);
33053310
o.write_shift(4, data.iTabID);
33063311
write_RelID(data.strRelID, o);
3307-
write_XLWideString(data.name, o);
3312+
write_XLWideString(data.name.substr(0,31), o);
33083313
return o;
33093314
};
33103315

dist/xlsx.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/xlsx.min.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ describe('invalid files', function() {
639639
].forEach(function(w) { it('should fail on ' + w[0], function() {
640640
assert.throws(function() { X.readFile(dir + w[1]); });
641641
assert.throws(function() { X.read(fs.readFileSync(dir+w[1], 'base64'), {type:'base64'}); });
642-
}); });
642+
}); });
643643
});
644644
describe('write', function() {
645645
it('should pass', function() { X.write(X.readFile(paths.fst1), {type:'binary'}); });
@@ -680,7 +680,7 @@ function sheet_from_array_of_arrays(data, opts) {
680680
for(var C = 0; C != data[R].length; ++C) {
681681
if(range.s.r > R) range.s.r = R;
682682
if(range.s.c > C) range.s.c = C;
683-
if(range.e.r < R) range.e.r = R;
683+
if(range.e.r < R) range.e.r = R;
684684
if(range.e.c < C) range.e.c = C;
685685
var cell = {v: data[R][C] };
686686
if(cell.v == null) continue;

xlsx.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,6 @@ var rencstr = "&<>'\"".split("");
677677
function unescapexml(text){
678678
var s = text + '';
679679
s = s.replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&amp;/g, "&");
680-
//for(var y in encodings) s = s.replace(new RegExp(y,'g'), encodings[y]);
681680
return s.replace(/_x([0-9a-fA-F]*)_/g,function(m,c) {return _chr(parseInt(c,16));});
682681
}
683682
function escapexml(text){
@@ -2506,31 +2505,37 @@ function parse_ws_xml(data, opts, rels) {
25062505
}
25072506

25082507
var refguess = {s: {r:1000000, c:1000000}, e: {r:0, c:0} };
2509-
var q = (opts.cellFormula ? ["v","f"] : ["v"]);
25102508
var sidx = 0;
25112509

2510+
var match_v = matchtag("v"), match_f = matchtag("f");
25122511
/* 18.3.1.80 sheetData CT_SheetData ? */
2513-
if((mtch=data.match(/<(?:\w+:)?sheetData>([^\u2603]*)<\/(?:\w+:)?sheetData>/m))) mtch[1].split(/<\/(?:\w+:)?row>/).forEach(function(x) {
2514-
if(x === "" || x.trim() === "") return;
2512+
mtch=data.match(/<(?:\w+:)?sheetData>([^\u2603]*)<\/(?:\w+:)?sheetData>/m);
2513+
if(mtch) for(var marr = mtch[1].split(/<\/(?:\w+:)?row>/), mt = 0; mt != marr.length; ++mt) {
2514+
x = marr[mt];
2515+
if(x === "" || x.trim() === "") continue;
25152516

25162517
/* 18.3.1.73 row CT_Row */
25172518
var row = parsexmltag(x.match(/<(?:\w+:)?row[^>]*>/)[0]);
2518-
if(opts.sheetRows && opts.sheetRows < +row.r) return;
2519+
if(opts.sheetRows && opts.sheetRows < +row.r) continue;
25192520
if(refguess.s.r > row.r - 1) refguess.s.r = row.r - 1;
25202521
if(refguess.e.r < row.r - 1) refguess.e.r = row.r - 1;
25212522
/* 18.3.1.4 c CT_Cell */
25222523
var cells = x.substr(x.indexOf('>')+1).split(/<(?:\w+:)?c /);
2523-
cells.forEach(function(c, idx) { if(c === "" || c.trim() === "") return;
2524-
var cref = c.match(/r=["']([^"']*)["']/);
2524+
for(var ix = 0, c=cells[0]; ix != cells.length; ++ix,c=cells[ix]) {
2525+
if(c === "" || c.trim() === "") continue;
2526+
var cref = c.match(/r=["']([^"']*)["']/), idx = ix;
25252527
c = "<c " + c;
25262528
if(cref && cref.length == 2) idx = decode_cell(cref[1]).c;
25272529
var cell = parsexmltag((c.match(/<c[^>]*>/)||[c])[0]); delete cell[0];
25282530
var d = c.substr(c.indexOf('>')+1);
25292531
var p = {};
2530-
q.forEach(function(f){var x=d.match(matchtag(f));if(x)p[f]=unescapexml(x[1]);});
2532+
2533+
var x=d.match(match_v);if(x)p.v=unescapexml(x[1]);
2534+
if(opts.cellFormula) {x=d.match(match_f);if(x)p.f=unescapexml(x[1]);}
2535+
25312536
/* SCHEMA IS ACTUALLY INCORRECT HERE. IF A CELL HAS NO T, EMIT "" */
25322537
if(cell.t === undefined && p.v === undefined) {
2533-
if(!opts.sheetStubs) return;
2538+
if(!opts.sheetStubs) continue;
25342539
p.t = "str"; p.v = undefined;
25352540
}
25362541
else p.t = (cell.t ? cell.t : "n"); // default is "n" in schema
@@ -2581,8 +2586,8 @@ function parse_ws_xml(data, opts, rels) {
25812586
}
25822587
} catch(e) { if(opts.WTF) throw e; }
25832588
s[cell.r] = p;
2584-
});
2585-
});
2589+
};
2590+
}
25862591

25872592
/* 18.3.1.48 hyperlinks CT_Hyperlinks */
25882593
if(data.match(/<\/hyperlinks>/)) data.match(/<hyperlink[^>]*\/>/g).forEach(function(h) {
@@ -3283,7 +3288,7 @@ var write_wb_xml = function(wb, opts) {
32833288
o.push("<sheets>");
32843289
var i = 1;
32853290
wb.SheetNames.forEach(function(s) {
3286-
o.push(writextag('sheet',null,{name:s, sheetId:String(i), "r:id":"rId"+i}));
3291+
o.push(writextag('sheet',null,{name:s.substr(0,31), sheetId:String(i), "r:id":"rId"+i}));
32873292
++i;
32883293
});
32893294
o.push("</sheets>");
@@ -3304,7 +3309,7 @@ var write_BrtBundleSh = function(data, o) {
33043309
o.write_shift(4, data.hsState);
33053310
o.write_shift(4, data.iTabID);
33063311
write_RelID(data.strRelID, o);
3307-
write_XLWideString(data.name, o);
3312+
write_XLWideString(data.name.substr(0,31), o);
33083313
return o;
33093314
};
33103315

0 commit comments

Comments
 (0)