A local-first personal finance app
Fix bug in ofx2json logic (#4838)
Julian Dominguez-Schatzf1594e5bcaf7
diff --git a/packages/loot-core/src/server/transactions/import/__snapshots__/parse-file.test.ts.snap b/packages/loot-core/src/server/transactions/import/__snapshots__/parse-file.test.ts.snapindex 1fbe231b13..b2a9d70f6c 100644--- a/packages/loot-core/src/server/transactions/import/__snapshots__/parse-file.test.ts.snap+++ b/packages/loot-core/src/server/transactions/import/__snapshots__/parse-file.test.ts.snap@@ -232,7 +232,7 @@ exports[`File import handles html escaped plaintext 1`] = `"error": null,"financial_id": "23060061032549554596530000","id": "id5",- "imported_description": "TPAY <DEFTPYMT>",+ "imported_description": "TPAY <DEFTPYMT>","isChild": 0,"isParent": 0,"location": null,diff --git a/packages/loot-core/src/server/transactions/import/ofx2json.test.ts b/packages/loot-core/src/server/transactions/import/ofx2json.test.tsnew file mode 100644index 0000000000..87c842a922--- /dev/null+++ b/packages/loot-core/src/server/transactions/import/ofx2json.test.ts@@ -0,0 +1,33 @@+import { html2Plain } from './ofx2json';++describe('html2Plain', () => {+ test('regular text works', async () => {+ expect(html2Plain('Hello, world!')).toBe('Hello, world!');+ expect(html2Plain('Hello, <b>world</b>!')).toBe('Hello, <b>world</b>!');+ });++ test('brackets are unescaped', async () => {+ expect(html2Plain('Hello, <world>!')).toBe('Hello, <world>!');+ });+ test('apostrophes are unescaped', async () => {+ expect(html2Plain('Hello, 'world'!')).toBe("Hello, 'world'!");+ });+ test('quotes are unescaped', async () => {+ expect(html2Plain('Hello, "world"!')).toBe('Hello, "world"!');+ });+ test('ampersands are unescaped', async () => {+ expect(html2Plain('Hello, &world&!')).toBe('Hello, &world&!');+ expect(html2Plain('Hello, &world&!')).toBe('Hello, &world&!');+ });+ test('no double unescaping with other entities', async () => {+ expect(html2Plain('Hello, &#038;world&#038;!')).toBe(+ 'Hello, &world&!',+ );+ expect(html2Plain('Hello, &amp;world&amp;!')).toBe(+ 'Hello, &world&!',+ );+ expect(html2Plain('Hello, &quot;world&quot;!')).toBe(+ 'Hello, "world"!',+ );+ });+});diff --git a/packages/loot-core/src/server/transactions/import/ofx2json.ts b/packages/loot-core/src/server/transactions/import/ofx2json.tsindex 91fc8abeb5..20a888ab4d 100644--- a/packages/loot-core/src/server/transactions/import/ofx2json.ts+++ b/packages/loot-core/src/server/transactions/import/ofx2json.ts@@ -29,14 +29,13 @@ function sgml2Xml(sgml) {.replace(/<\/<added>(\w+?)>(<\/\1>)?/g, '</$1>'); // Remove duplicate end-tags}-function html2Plain(value) {+export function html2Plain(value) {return value- ?.replace(/&/g, '&') // ampersands- .replace(/&/g, '&') // other ampersands- .replace(/</g, '<') // lessthan+ ?.replace(/</g, '<') // lessthan.replace(/>/g, '>') // greaterthan.replace(/'/g, "'") // eslint-disable-line rulesdir/typography- .replace(/"/g, '"'); // eslint-disable-line rulesdir/typography+ .replace(/"/g, '"') // eslint-disable-line rulesdir/typography+ .replace(/(&|&)/g, '&'); // ampersands}async function parseXml(content) {diff --git a/upcoming-release-notes/4838.md b/upcoming-release-notes/4838.mdnew file mode 100644index 0000000000..b13782d8e3--- /dev/null+++ b/upcoming-release-notes/4838.md@@ -0,0 +1,6 @@+---+category: Bugfix+authors: [jfdoming]+---++Fix HTML bug in ofx2json logic