Skip to content

A local-first personal finance app

fix: validate that transaction amounts are integers during import (#7812) (#7891)

KarelTestSpecial887640af69b4
diff --git a/packages/loot-core/src/server/accounts/sync.ts b/packages/loot-core/src/server/accounts/sync.ts
index 89cd3e1e13..ce3f634f60 100644
--- a/packages/loot-core/src/server/accounts/sync.ts
+++ b/packages/loot-core/src/server/accounts/sync.ts
@@ -7,6 +7,7 @@ import { logger } from '#platform/server/log';
import { aqlQuery } from '#server/aql';
import * as db from '#server/db';
import { TRANSACTION_SORT_INCREMENT } from '#server/db/sort';
+import { TransactionError } from '#server/errors';
import { runMutator } from '#server/mutators';
import { post } from '#server/post';
import { getServer } from '#server/server-config';
@@ -389,6 +390,22 @@ async function normalizeTransactions(
const { payee_name: originalPayeeName, subtransactions, ...rest } = trans;
trans = rest;
+ if (trans.amount != null && !Number.isInteger(trans.amount)) {
+ throw new TransactionError(
+ `Amount is invalid, must be an integer: ${trans.amount}`,
+ );
+ }
+
+ if (subtransactions) {
+ for (const sub of subtransactions) {
+ if (sub.amount != null && !Number.isInteger(sub.amount)) {
+ throw new TransactionError(
+ `Subtransaction amount is invalid, must be an integer: ${sub.amount}`,
+ );
+ }
+ }
+ }
+
let payee_name = originalPayeeName;
if (payee_name) {
const trimmed = payee_name.trim();
diff --git a/upcoming-release-notes/7891.md b/upcoming-release-notes/7891.md
new file mode 100644
index 0000000000..49f17d366e
--- /dev/null
+++ b/upcoming-release-notes/7891.md
@@ -0,0 +1,6 @@
+---
+category: Bugfixes
+authors: [KarelTestSpecial]
+---
+
+Validate transaction amounts as integers during import to prevent data entry errors.