From c615f85034e7b4bae314368a2eef7f690ec6ec96 Mon Sep 17 00:00:00 2001 From: Srijon Saha <33412649+srijonsaha@users.noreply.github.com> Date: Tue, 16 Jun 2020 13:51:56 -0700 Subject: [PATCH] Fix issue with dbf parsing --- bits/40_harb.js | 4 +++- bits/87_read.js | 2 +- xlsx.flow.js | 6 ++++-- xlsx.js | 6 ++++-- xlsx.mini.flow.js | 2 +- xlsx.mini.js | 2 +- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/bits/40_harb.js b/bits/40_harb.js index ef00fb4..10369a7 100644 --- a/bits/40_harb.js +++ b/bits/40_harb.js @@ -55,6 +55,7 @@ var dbf_reverse_map = evert({ /*::[*/0xCA/*::]*/: 1254, /*::[*/0xCB/*::]*/: 1253, /*::[*/0x00/*::]*/: 20127 }); +var DBF_SUPPORTED_VERSIONS = [0x02, 0x03, 0x30, 0x31, 0x83, 0x8B, 0x8C, 0xF5]; /* TODO: find an actual specification */ function dbf_to_aoa(buf, opts)/*:AOA*/ { var out/*:AOA*/ = []; @@ -308,6 +309,7 @@ function sheet_to_dbf(ws/*:Worksheet*/, opts/*:WriteOpts*/) { return ba.end(); } return { + versions: DBF_SUPPORTED_VERSIONS, to_workbook: dbf_to_workbook, to_sheet: dbf_to_sheet, from_sheet: sheet_to_dbf @@ -820,7 +822,7 @@ var PRN = (function() { } // If line ends in \r OR \n else if(str.charCodeAt(5) == 13 || str.charCodeAt(5) == 10 ) { - // + // sep = str.charAt(4); str = str.slice(6); } } diff --git a/bits/87_read.js b/bits/87_read.js index 0e168e4..db0d3a9 100644 --- a/bits/87_read.js +++ b/bits/87_read.js @@ -95,7 +95,7 @@ function readSync(data/*:RawData*/, opts/*:?ParseOpts*/)/*:Workbook*/ { case 0x7B: if(n[1] === 0x5C && n[2] === 0x72 && n[3] === 0x74) return RTF.to_workbook(d, o); break; case 0x0A: case 0x0D: case 0x20: return read_plaintext_raw(d, o); } - if(n[2] <= 12 && n[3] <= 31) return DBF.to_workbook(d, o); + if(DBF.versions.indexOf(n[0]) > -1 && n[2] <= 12 && n[3] <= 31) return DBF.to_workbook(d, o); return read_prn(data, d, o, str); } diff --git a/xlsx.flow.js b/xlsx.flow.js index c504734..675a6c7 100644 --- a/xlsx.flow.js +++ b/xlsx.flow.js @@ -6914,6 +6914,7 @@ var dbf_reverse_map = evert({ /*::[*/0xCA/*::]*/: 1254, /*::[*/0xCB/*::]*/: 1253, /*::[*/0x00/*::]*/: 20127 }); +var DBF_SUPPORTED_VERSIONS = [0x02, 0x03, 0x30, 0x31, 0x83, 0x8B, 0x8C, 0xF5]; /* TODO: find an actual specification */ function dbf_to_aoa(buf, opts)/*:AOA*/ { var out/*:AOA*/ = []; @@ -7167,6 +7168,7 @@ function sheet_to_dbf(ws/*:Worksheet*/, opts/*:WriteOpts*/) { return ba.end(); } return { + versions: DBF_SUPPORTED_VERSIONS, to_workbook: dbf_to_workbook, to_sheet: dbf_to_sheet, from_sheet: sheet_to_dbf @@ -7679,7 +7681,7 @@ var PRN = (function() { } // If line ends in \r OR \n else if(str.charCodeAt(5) == 13 || str.charCodeAt(5) == 10 ) { - // + // sep = str.charAt(4); str = str.slice(6); } } @@ -20950,7 +20952,7 @@ function readSync(data/*:RawData*/, opts/*:?ParseOpts*/)/*:Workbook*/ { case 0x7B: if(n[1] === 0x5C && n[2] === 0x72 && n[3] === 0x74) return RTF.to_workbook(d, o); break; case 0x0A: case 0x0D: case 0x20: return read_plaintext_raw(d, o); } - if(n[2] <= 12 && n[3] <= 31) return DBF.to_workbook(d, o); + if(DBF.versions.indexOf(n[0]) > -1 && n[2] <= 12 && n[3] <= 31) return DBF.to_workbook(d, o); return read_prn(data, d, o, str); } diff --git a/xlsx.js b/xlsx.js index b491dd3..8023478 100644 --- a/xlsx.js +++ b/xlsx.js @@ -6817,6 +6817,7 @@ var dbf_reverse_map = evert({ 0xCA: 1254, 0xCB: 1253, 0x00: 20127 }); +var DBF_SUPPORTED_VERSIONS = [0x02, 0x03, 0x30, 0x31, 0x83, 0x8B, 0x8C, 0xF5]; /* TODO: find an actual specification */ function dbf_to_aoa(buf, opts) { var out = []; @@ -7069,6 +7070,7 @@ function sheet_to_dbf(ws, opts) { return ba.end(); } return { + versions: DBF_SUPPORTED_VERSIONS, to_workbook: dbf_to_workbook, to_sheet: dbf_to_sheet, from_sheet: sheet_to_dbf @@ -7581,7 +7583,7 @@ var PRN = (function() { } // If line ends in \r OR \n else if(str.charCodeAt(5) == 13 || str.charCodeAt(5) == 10 ) { - // + // sep = str.charAt(4); str = str.slice(6); } } @@ -20826,7 +20828,7 @@ function readSync(data, opts) { case 0x7B: if(n[1] === 0x5C && n[2] === 0x72 && n[3] === 0x74) return RTF.to_workbook(d, o); break; case 0x0A: case 0x0D: case 0x20: return read_plaintext_raw(d, o); } - if(n[2] <= 12 && n[3] <= 31) return DBF.to_workbook(d, o); + if(DBF.versions.indexOf(n[0]) > -1 && n[2] <= 12 && n[3] <= 31) return DBF.to_workbook(d, o); return read_prn(data, d, o, str); } diff --git a/xlsx.mini.flow.js b/xlsx.mini.flow.js index 6cb178b..057c253 100644 --- a/xlsx.mini.flow.js +++ b/xlsx.mini.flow.js @@ -8135,7 +8135,7 @@ function readSync(data/*:RawData*/, opts/*:?ParseOpts*/)/*:Workbook*/ { case 0x7B: if(n[1] === 0x5C && n[2] === 0x72 && n[3] === 0x74) return RTF.to_workbook(d, o); break; case 0x0A: case 0x0D: case 0x20: return read_plaintext_raw(d, o); } - if(n[2] <= 12 && n[3] <= 31) return DBF.to_workbook(d, o); + if(DBF.versions.indexOf(n[0]) > -1 && n[2] <= 12 && n[3] <= 31) return DBF.to_workbook(d, o); return read_prn(data, d, o, str); } diff --git a/xlsx.mini.js b/xlsx.mini.js index 703a91d..a1e22d2 100644 --- a/xlsx.mini.js +++ b/xlsx.mini.js @@ -8038,7 +8038,7 @@ function readSync(data, opts) { case 0x7B: if(n[1] === 0x5C && n[2] === 0x72 && n[3] === 0x74) return RTF.to_workbook(d, o); break; case 0x0A: case 0x0D: case 0x20: return read_plaintext_raw(d, o); } - if(n[2] <= 12 && n[3] <= 31) return DBF.to_workbook(d, o); + if(DBF.versions.indexOf(n[0]) > -1 && n[2] <= 12 && n[3] <= 31) return DBF.to_workbook(d, o); return read_prn(data, d, o, str); }