Skip to content
Snippets Groups Projects
Unverified Commit f7aa313a authored by Davis Silverman's avatar Davis Silverman Committed by GitHub
Browse files

Detect more errors in JS OFX importer. (#1005)

parent c9576d98
No related branches found
No related tags found
No related merge requests found
...@@ -196,16 +196,24 @@ async function parseOFX(filepath) { ...@@ -196,16 +196,24 @@ async function parseOFX(filepath) {
async function parseOfxJavascript(filepath) { async function parseOfxJavascript(filepath) {
let errors = []; let errors = [];
// 'binary' should be equal to latin1 in node.js
// not sure about browser. We want latin1 and not utf8.
// For some reason, utf8 does not parse ofx files correctly here.
const contents = new TextDecoder('latin1').decode(
(await fs.readFile(filepath, 'binary')) as Buffer,
);
let data; let data;
let transactions;
try { try {
// 'binary' should be equal to latin1 in node.js
// not sure about browser. We want latin1 and not utf8.
// For some reason, utf8 does not parse ofx files correctly here.
const contents = new TextDecoder('latin1').decode(
(await fs.readFile(filepath, 'binary')) as Buffer,
);
data = ofx.parse(contents); data = ofx.parse(contents);
// .STMTTRN may be a list or a single object.
transactions = [
(
data.body.OFX.BANKMSGSRSV1?.STMTTRNRS.STMTRS ||
data.body.OFX.CREDITCARDMSGSRSV1?.CCSTMTTRNRS.CCSTMTRS
).BANKTRANLIST.STMTTRN,
].flat();
} catch (err) { } catch (err) {
errors.push({ errors.push({
message: 'Failed importing file', message: 'Failed importing file',
...@@ -213,13 +221,6 @@ async function parseOfxJavascript(filepath) { ...@@ -213,13 +221,6 @@ async function parseOfxJavascript(filepath) {
}); });
return { errors }; return { errors };
} }
// .STMTTRN may be a list or a single object.
const transactions = [
(
data.body.OFX.BANKMSGSRSV1?.STMTTRNRS.STMTRS ||
data.body.OFX.CREDITCARDMSGSRSV1?.CCSTMTTRNRS.CCSTMTRS
).BANKTRANLIST.STMTTRN,
].flat();
return { return {
errors, errors,
transactions: transactions.map(trans => ({ transactions: transactions.map(trans => ({
......
---
category: Maintenance
authors: [Sinistersnare]
---
Detect more errors in JS OFX importer.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment