Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converts html special characters in ofx values to plaintext #2364

Merged
merged 2 commits into from
Feb 17, 2024
Merged
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
17 changes: 17 additions & 0 deletions packages/loot-core/src/mocks/files/html-vals.qfx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
OFXHEADER:100
DATA:OFXSGML
VERSION:102
SECURITY:NONE
ENCODING:USASCII
CHARSET:1252
COMPRESSION:NONE
OLDFILEUID:NONE
NEWFILEUID:NONE

<OFX><SIGNONMSGSRSV1><SONRS><STATUS><CODE>0<SEVERITY>INFO<MESSAGE>OK</STATUS><DTSERVER>20231106023518<LANGUAGE>ENG<DTPROFUP>20231106023518<DTACCTUP>20231106023518<INTU.BID>00005</SONRS></SIGNONMSGSRSV1>
<BANKMSGSRSV1><STMTTRNRS><TRNUID>20231106023518<STATUS><CODE>0<SEVERITY>INFO<MESSAGE>OK</STATUS>
<STMTRS><CURDEF>CAD<BANKACCTFROM><BANKID>000000000<ACCTID>00000 00-00000<ACCTTYPE>CHECKING</BANKACCTFROM>
<BANKTRANLIST><DTSTART>20190731120000<DTEND>20231031120000
<STMTTRN><TRNTYPE>DEBIT<DTPOSTED>20230509120000.000[-5:EST]<TRNAMT>-1.00<FITID>23129130032333396279270000<NAME>000000000000000<MEMO>PREAUTHORIZED DEBIT;B.C. HYDRO &amp; POWER AUTHORITY;Electronic Funds Transfer</STMTTRN>
<STMTTRN><TRNTYPE>DEBIT<DTPOSTED>20230301120000.000[-5:EST]<TRNAMT>-1.00<FITID>23060061032549554596530000<NAME>TPAY &amp;lt;DEFTPYMT&amp;gt;<MEMO>PREAUTHORIZED DEBIT;LUXMORE REALTY PPTY MGMT;Electronic Funds Transfer</STMTTRN>
</BANKTRANLIST><LEDGERBAL><BALAMT>1111.11<DTASOF>20231106023518</LEDGERBAL><AVAILBAL><BALAMT>1111.11<DTASOF>20231106023518</AVAILBAL></STMTRS></STMTTRNRS></BANKMSGSRSV1></OFX>
Original file line number Diff line number Diff line change
@@ -1,5 +1,60 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`File import handles html escaped plaintext 1`] = `
Array [
Object {
"acct": "one",
"amount": -100,
"category": null,
"cleared": 1,
"date": 20230509,
"description": "id2",
"error": null,
"financial_id": "23129130032333396279270000",
"id": "id4",
"imported_description": "000000000000000",
"isChild": 0,
"isParent": 0,
"location": null,
"notes": "PREAUTHORIZED DEBIT;B.C. HYDRO & POWER AUTHORITY;Electronic Funds Transfer",
"parent_id": null,
"pending": 0,
"reconciled": 0,
"schedule": null,
"sort_order": 123456789,
"starting_balance_flag": 0,
"tombstone": 0,
"transferred_id": null,
"type": null,
},
Object {
"acct": "one",
"amount": -100,
"category": null,
"cleared": 1,
"date": 20230301,
"description": "id3",
"error": null,
"financial_id": "23060061032549554596530000",
"id": "id5",
"imported_description": "TPAY <DEFTPYMT>",
"isChild": 0,
"isParent": 0,
"location": null,
"notes": "PREAUTHORIZED DEBIT;LUXMORE REALTY PPTY MGMT;Electronic Funds Transfer",
"parent_id": null,
"pending": 0,
"reconciled": 0,
"schedule": null,
"sort_order": 123456789,
"starting_balance_flag": 0,
"tombstone": 0,
"transferred_id": null,
"type": null,
},
]
`;

exports[`File import handles non-ASCII characters 1`] = `
Array [
Object {
Expand Down
14 changes: 12 additions & 2 deletions packages/loot-core/src/server/accounts/ofx2json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
.replace(/<\/<added>(\w+?)>(<\/\1>)?/g, '</$1>'); // Remove duplicate end-tags
}

function html2Plain(value) {
return value
?.replace(/&amp;/g, '&') // ampersands
Dismissed Show dismissed Hide dismissed
.replace(/&#038;/g, '&') // other ampersands
github-advanced-security[bot] marked this conversation as resolved.
Dismissed
Show resolved Hide resolved
.replace(/&lt;/g, '<') // lessthan
.replace(/&gt;/g, '>') // greaterthan
.replace(/&#39;/g, "'") // eslint-disable-line rulesdir/typography
.replace(/&quot;/g, '"'); // eslint-disable-line rulesdir/typography
}

async function parseXml(content) {
return await parseStringPromise(content, { explicitArray: false });
}
Expand Down Expand Up @@ -106,8 +116,8 @@
type: stmtTrn['TRNTYPE'],
fitId: stmtTrn['FITID'],
date: dayFromDate(transactionDate),
name: stmtTrn['NAME'],
memo: stmtTrn['MEMO'],
name: html2Plain(stmtTrn['NAME']),
memo: html2Plain(stmtTrn['MEMO']),
};
}

Expand Down
13 changes: 13 additions & 0 deletions packages/loot-core/src/server/accounts/parse-file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,17 @@ describe('File import', () => {
expect(errors.length).toBe(0);
expect(await getTransactions('one')).toMatchSnapshot();
});

test('handles html escaped plaintext', async () => {
prefs.loadPrefs();
await db.insertAccount({ id: 'one', name: 'one' });

const { errors } = await importFileWithRealTime(
'one',
__dirname + '/../../mocks/files/html-vals.qfx',
'yyyy-MM-dd',
);
expect(errors.length).toBe(0);
expect(await getTransactions('one')).toMatchSnapshot();
});
});
6 changes: 6 additions & 0 deletions upcoming-release-notes/2364.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [twk3]
---

Convert html special characters in ofx imports to plaintext.
Loading