Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ describe("xlsx", function() {
var { createFiles, createXlsx } = require("..")
, compressionSuported = typeof CompressionStream !== "undefined" && typeof Response !== "undefined"

test("XML 1.0 characters", function(assert) {
var text = 'A\u0000\u0001\u0008\u000b\u000c\u000e\u001f\ud800B\udfff\ufffe\uffffC\t\n\r\ud83d\ude00'
, clean = 'ABC\t\n\r\ud83d\ude00'
, files = createFiles({ sheets: [{ name: text, data: [[text]] }] })
, workbook = files.find(f => f.name === 'xl/workbook.xml').content
, sheet = files.find(f => f.name === 'xl/worksheets/sheet1.xml').content
assert.ok(workbook.includes('name="' + clean + '"'), 'attributes omit invalid code points')
assert.ok(sheet.includes('>' + clean + '</t>'), 'text preserves whitespace and supplementary characters')
assert.end()
})

function sheet1(data, sheet) {
return createFiles({ sheets: [{ data, ...sheet }] }).find(f => f.name === 'xl/worksheets/sheet1.xml').content
}
Expand Down
3 changes: 1 addition & 2 deletions xlsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
, excelEpoch = Date.UTC(1899, 11, 30)
, assign = Object.assign
, dataArr = arr => Array.isArray(arr) ? { data: arr } : arr
, esc = val => ('' + val).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, '')
, esc = val => ('' + val).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\uFFFE\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDFFF]/g, c => c.length === 2 ? c : '')
, isNum = num => num === num && typeof num === 'number'
, isObj = obj => !!obj && obj.constructor === Object
, isStr = str => typeof str === 'string'
Expand Down Expand Up @@ -207,4 +207,3 @@

// this is `exports` in module and `window` in browser
})(this, Object) // jshint ignore:line

Loading