Escape embedded quotes

This commit is contained in:
Pieter Sheth-Voss 2015-03-03 14:27:28 -05:00
parent 576b59f96a
commit 05b58d839a
6 changed files with 33 additions and 28 deletions

@ -1,12 +1,7 @@
function writeSync(wb, opts) {
var o = opts||{};
if (typeof module != 'undefined' && typeof 'require' != 'undefined') {
style_builder = new StyleBuilder(opts);
}
else if (typeof $ != 'undefined' || typeof 'jQuery' != 'undefined') {
style_builder = new StyleBuilder(opts);
}
console.log("Creating stylebuilder")
style_builder = new StyleBuilder(opts);
var z = write_zip(wb, o);
switch(o.type) {

@ -49,13 +49,17 @@ var XmlNode = (function () {
return this;
}
XmlNode.prototype.escapeString = function(str) {
return str.replace(/\"/g,'"') // TODO Extend with four other codes
}
XmlNode.prototype.toXml = function (node) {
if (!node) node = this;
var xml = node._prefix;
xml += '<' + node.tagName;
if (node._attributes) {
for (var key in node._attributes) {
xml += ' ' + key + '="' + node._attributes[key] + '"'
xml += ' ' + key + '="' + this.escapeString(''+node._attributes[key]) + '"'
}
}
if (node._children && node._children.length > 0) {

@ -35,9 +35,7 @@ if ((typeof 'module' != 'undefined' && typeof require != 'undefined') || (typeo
47: 'mmss.0',
48: '##0.0E+0',
49: '@',
56: '"上午/下午 "hh"時"mm"分"ss"秒 "',
65535: 'General'
};
56: '"上午/下午 "hh"時"mm"分"ss"秒 "' };
var fmt_table = {};
for (var idx in table_fmt) {
@ -99,7 +97,7 @@ if ((typeof 'module' != 'undefined' && typeof require != 'undefined') || (typeo
// the second style MUST be gray125 for some reason
var defaultStyle = options.defaultCellStyle || {};
if (!defaultStyle.font) defaultStyle.font = {name: 'Calibri', sz: '11'};
if (!defaultStyle.font) defaultStyle.font = {name: 'Calibri', sz: '12'};
if (!defaultStyle.font.name) defaultStyle.font.name = 'Calibri';
if (!defaultStyle.font.sz) defaultStyle.font.sz = 11;
if (!defaultStyle.fill) defaultStyle.fill = { fgColor: { patternType: "none"}};

0
test-csv.js Normal file

19
test.js

@ -107,9 +107,18 @@ function parsetest(x, wb, full, ext) {
wb.SheetNames.forEach(function(ws, i) {
var name = getfile(dir, x, i, ".csv");
it('#' + i + ' (' + ws + ')', fs.existsSync(name) ? function() {
var file = fs.readFileSync(name, 'utf-8');
var csv = X.utils.make_csv(wb.Sheets[ws]);
assert.equal(fixcsv(csv), fixcsv(file), "CSV badness");
var file = fixcsv(fs.readFileSync(name, 'utf-8'));
var csv = fixcsv(X.utils.make_csv(wb.Sheets[ws]));
var result = (file == csv);
if (!result) {
console.error(dir + x);
console.error("========== actual =============")
console.error(csv);
console.error("---------- expected -----------")
console.error(file);
console.error("LENGTHS: "+[csv.length, file.length])
}
assert.equal(result, true, "CSV badness");
} : null);
});
});
@ -152,7 +161,9 @@ describe('should parse test files', function() {
it(x + ' [' + ext + ']', function(){
var wb = wbtable[dir + x];
if(!wb) wb = X.readFile(dir + x, opts);
parsetest(x, X.read(X.write(wb, {type:"buffer", bookType:ext.replace(/\./,"")}), {WTF:opts.WTF}), ext.replace(/\./,"") !== "xlsb", ext);
//wb = X.read(X.write(wb, {type:"buffer", bookType:ext.replace(/\./,"")}), {WTF:opts.WTF})
// wb = X.read(X.write(wb, {type:"buffer", bookType:'xlsx'}));
parsetest(x, wb, ext.replace(/\./,"") !== "xlsb", ext);
});
});
});

21
xlsx.js

@ -5184,13 +5184,8 @@ function readFileSync(data, opts) {
function writeSync(wb, opts) {
var o = opts||{};
if (typeof module != 'undefined' && typeof 'require' != 'undefined') {
style_builder = new StyleBuilder(opts);
}
else if (typeof $ != 'undefined' || typeof 'jQuery' != 'undefined') {
style_builder = new StyleBuilder(opts);
}
console.log("Creating stylebuilder")
style_builder = new StyleBuilder(opts);
var z = write_zip(wb, o);
switch(o.type) {
@ -5466,13 +5461,17 @@ var XmlNode = (function () {
return this;
}
XmlNode.prototype.escapeString = function(str) {
return str.replace(/\"/g,'&quot;') // TODO Extend with four other codes
}
XmlNode.prototype.toXml = function (node) {
if (!node) node = this;
var xml = node._prefix;
xml += '<' + node.tagName;
if (node._attributes) {
for (var key in node._attributes) {
xml += ' ' + key + '="' + node._attributes[key] + '"'
xml += ' ' + key + '="' + this.escapeString(''+node._attributes[key]) + '"'
}
}
if (node._children && node._children.length > 0) {
@ -5526,9 +5525,7 @@ if ((typeof 'module' != 'undefined' && typeof require != 'undefined') || (typeo
47: 'mmss.0',
48: '##0.0E+0',
49: '@',
56: '"上午/下午 "hh"時"mm"分"ss"秒 "',
65535: 'General'
};
56: '"上午/下午 "hh"時"mm"分"ss"秒 "' };
var fmt_table = {};
for (var idx in table_fmt) {
@ -5590,7 +5587,7 @@ if ((typeof 'module' != 'undefined' && typeof require != 'undefined') || (typeo
// the second style MUST be gray125 for some reason
var defaultStyle = options.defaultCellStyle || {};
if (!defaultStyle.font) defaultStyle.font = {name: 'Calibri', sz: '11'};
if (!defaultStyle.font) defaultStyle.font = {name: 'Calibri', sz: '12'};
if (!defaultStyle.font.name) defaultStyle.font.name = 'Calibri';
if (!defaultStyle.font.sz) defaultStyle.font.sz = 11;
if (!defaultStyle.fill) defaultStyle.fill = { fgColor: { patternType: "none"}};