Skip to content

A local-first personal finance app

Fix date validation bug causing crashes with old dates (#5970)

Matiss Janis Aboltinsddbefc790e80
diff --git a/packages/loot-core/src/server/aql/schema-helpers.test.ts b/packages/loot-core/src/server/aql/schema-helpers.test.ts
index 40239930e3..fd8215dbb8 100644
--- a/packages/loot-core/src/server/aql/schema-helpers.test.ts
+++ b/packages/loot-core/src/server/aql/schema-helpers.test.ts
@@ -209,4 +209,34 @@ describe('schema-helpers', () => {
});
}).toThrow('Can’t convert to integer');
});
+
+ test('dates before 2000-01-01 are rejected', () => {
+ expect(() => {
+ convertForInsert(basicSchema, {}, 'transactions', {
+ id: 't1',
+ account: 'foo',
+ amount: 5,
+ date: '1999-12-31',
+ });
+ }).toThrow('Invalid date: 1999-12-31');
+
+ expect(() => {
+ convertForInsert(basicSchema, {}, 'transactions', {
+ id: 't1',
+ account: 'foo',
+ amount: 5,
+ date: '1900-01-01',
+ });
+ }).toThrow('Invalid date: 1900-01-01');
+ });
+
+ test('dates on or after 2000-01-01 are accepted', () => {
+ const trans = convertForInsert(basicSchema, {}, 'transactions', {
+ id: 't1',
+ account: 'foo',
+ amount: 5,
+ date: '2000-01-01',
+ });
+ expect(trans.date).toBe(20000101);
+ });
});
diff --git a/packages/loot-core/src/server/aql/schema-helpers.ts b/packages/loot-core/src/server/aql/schema-helpers.ts
index 7bce6f5de5..ddf71cb9e3 100644
--- a/packages/loot-core/src/server/aql/schema-helpers.ts
+++ b/packages/loot-core/src/server/aql/schema-helpers.ts
@@ -25,7 +25,7 @@ export function convertInputType(value, type) {
return toDateRepr(dayFromDate(value));
} else if (
value.match(/^\d{4}-\d{2}-\d{2}$/) == null ||
- value.date < '2000-01-01'
+ value < '2000-01-01'
) {
throw new Error('Invalid date: ' + value);
}
diff --git a/upcoming-release-notes/5970.md b/upcoming-release-notes/5970.md
new file mode 100644
index 0000000000..3ef7820f33
--- /dev/null
+++ b/upcoming-release-notes/5970.md
@@ -0,0 +1,7 @@
+---
+category: Bugfix
+authors: [MatissJanis]
+---
+
+Fix budget crash when transactions have dates before year 2000
+