A local-first personal finance app
[AI] fix: match no transactions when "has tags" input lacks `#` (closes #7797) (#7808)
Maksim Zhukau2e0342574f9f
diff --git a/packages/loot-core/src/server/transactions/transaction-rules.test.ts b/packages/loot-core/src/server/transactions/transaction-rules.test.tsindex 5d6e6f0727..d283cf25f2 100644--- a/packages/loot-core/src/server/transactions/transaction-rules.test.ts+++ b/packages/loot-core/src/server/transactions/transaction-rules.test.ts@@ -540,6 +540,38 @@ describe('Transaction rules', () => {expect(transactions.map(t => t.id)).toEqual(['1']);});+ test('hasTags matches nothing when input contains no `#` tag pattern', async () => {+ await loadRules();+ const account = await db.insertAccount({ name: 'bank' });+ const payeeId = await db.insertPayee({ name: 'payee' });++ await db.insertTransaction({+ id: '1',+ date: '2020-10-01',+ account,+ payee: payeeId,+ notes: 'Follow up #foo issue',+ amount: 123,+ });++ await db.insertTransaction({+ id: '2',+ date: '2020-10-01',+ account,+ payee: payeeId,+ notes: 'unrelated note',+ amount: 123,+ });++ // Input is missing the leading `#` — previously this returned every+ // transaction; now it should match nothing.+ const transactions = await getMatchingTransactions([+ { field: 'notes', op: 'hasTags', value: 'foo' },+ ]);++ expect(transactions).toEqual([]);+ });+test('and sub expression builds $and condition', async () => {const conds = [{ field: 'category', op: 'is', value: null }];const { filters } = conditionsToAQL(conds);diff --git a/packages/loot-core/src/server/transactions/transaction-rules.ts b/packages/loot-core/src/server/transactions/transaction-rules.tsindex e8b2e67d82..498850270b 100644--- a/packages/loot-core/src/server/transactions/transaction-rules.ts+++ b/packages/loot-core/src/server/transactions/transaction-rules.ts@@ -623,6 +623,12 @@ export function conditionsToAQL(}}+ if (tagValues.length === 0) {+ // No `#tag` patterns in the input — match nothing rather than+ // returning an empty `$and` (which would match every row).+ return { id: null };+ }+return {$and: tagValues.map(v => {const escapedTag = vdiff --git a/upcoming-release-notes/7808.md b/upcoming-release-notes/7808.mdnew file mode 100644index 0000000000..bfc6d89e47--- /dev/null+++ b/upcoming-release-notes/7808.md@@ -0,0 +1,6 @@+---+category: Bugfixes+authors: [MaksZhukov]+---++Fix the "Notes > has tags" transaction filter returning every transaction when the input is missing a `#` — it now matches nothing instead.