A local-first personal finance app
fix(csv-import): trim whitespace from amount strings before parsing (#7149)
mibragimovedce092ae89b
diff --git a/packages/loot-core/src/shared/util.test.ts b/packages/loot-core/src/shared/util.test.tsindex c76ce8b320..db9406d0e2 100644--- a/packages/loot-core/src/shared/util.test.ts+++ b/packages/loot-core/src/shared/util.test.ts@@ -72,6 +72,15 @@ describe('utility functions', () => {expect(looselyParseAmount('(1 500.99)')).toBe(-1500.99);});+ test('looseParseAmount handles trailing whitespace', () => {+ expect(looselyParseAmount('1055 ')).toBe(1055);+ expect(looselyParseAmount('$1,055 ')).toBe(1055);+ expect(looselyParseAmount('$1,055.00 ')).toBe(1055);+ expect(looselyParseAmount(' $1,055 ')).toBe(1055);+ expect(looselyParseAmount('3.45 ')).toBe(3.45);+ expect(looselyParseAmount(' 3.45 ')).toBe(3.45);+ });+test('number formatting works with comma-dot format', () => {setNumberFormat({ format: 'comma-dot', hideFraction: false });let formatter = getNumberFormat().formatter;diff --git a/packages/loot-core/src/shared/util.ts b/packages/loot-core/src/shared/util.tsindex 5fe94ba90e..b5efdcce9e 100644--- a/packages/loot-core/src/shared/util.ts+++ b/packages/loot-core/src/shared/util.ts@@ -550,6 +550,8 @@ export function looselyParseAmount(amount: string) {return v.replace(/[^0-9-]/g, '');}+ amount = amount.trim();+if (amount.startsWith('(') && amount.endsWith(')')) {// Remove Unicode minus inside parentheses before converting to ASCII minusamount = amount.replace(/\u2212/g, '');diff --git a/upcoming-release-notes/7149.md b/upcoming-release-notes/7149.mdnew file mode 100644index 0000000000..5f09c896ad--- /dev/null+++ b/upcoming-release-notes/7149.md@@ -0,0 +1,6 @@+---+category: Bugfixes+authors: [mibragimov]+---++Fix CSV import incorrectly parsing transaction amounts that contain trailing whitespace (e.g. amounts from Excel-saved CSV files).