Skip to content

A local-first personal finance app

Extend normalisation utility for non-latin diacritic character handling (#7284)

James Skinner477b1873e21f
diff --git a/packages/loot-core/src/shared/normalisation.test.ts b/packages/loot-core/src/shared/normalisation.test.ts
new file mode 100644
index 0000000000..0fe593cb96
--- /dev/null
+++ b/packages/loot-core/src/shared/normalisation.test.ts
@@ -0,0 +1,39 @@
+import { describe, expect, it } from 'vitest';
+
+import { getNormalisedString } from './normalisation';
+
+describe('getNormalisedString', () => {
+ it('lowercases plain ASCII', () => {
+ expect(getNormalisedString('Hello World')).toBe('hello world');
+ });
+
+ it('strips standard diacritics', () => {
+ expect(getNormalisedString('café')).toBe('cafe');
+ expect(getNormalisedString('naïve')).toBe('naive');
+ expect(getNormalisedString('résumé')).toBe('resume');
+ });
+
+ it('matches a word with ą when searching a', () => {
+ expect(getNormalisedString('Pączek')).toBe('paczek');
+ });
+
+ it('matches a word with ł when searching with l', () => {
+ expect(getNormalisedString('Złoty')).toBe('zloty');
+ expect(getNormalisedString('Łódź')).toBe('lodz');
+ });
+
+ it('maps ß to ss', () => {
+ expect(getNormalisedString('Straße')).toBe('strasse');
+ expect(getNormalisedString('STRAẞE')).toBe('strasse');
+ });
+
+ it('maps ø to o', () => {
+ expect(getNormalisedString('Bjørn')).toBe('bjorn');
+ expect(getNormalisedString('Øresund')).toBe('oresund');
+ });
+
+ it('maps œ to oe', () => {
+ expect(getNormalisedString('Œuf')).toBe('oeuf');
+ expect(getNormalisedString('œuf')).toBe('oeuf');
+ });
+});
diff --git a/packages/loot-core/src/shared/normalisation.ts b/packages/loot-core/src/shared/normalisation.ts
index ab196c20fc..1e5abd3e24 100644
--- a/packages/loot-core/src/shared/normalisation.ts
+++ b/packages/loot-core/src/shared/normalisation.ts
@@ -1,6 +1,15 @@
+const iMap: Record<string, string> = {
+ ł: 'l',
+ ø: 'o',
+ ß: 'ss',
+ œ: 'oe',
+};
+const iRegex = new RegExp(Object.keys(iMap).join('|'), 'g');
+
export function getNormalisedString(value: string) {
return value
.toLowerCase()
+ .replace(iRegex, m => iMap[m])
.normalize('NFD')
.replace(/\p{Diacritic}/gu, '');
}
diff --git a/upcoming-release-notes/7284.md b/upcoming-release-notes/7284.md
new file mode 100644
index 0000000000..ca716a301e
--- /dev/null
+++ b/upcoming-release-notes/7284.md
@@ -0,0 +1,6 @@
+---
+category: Bugfixes
+authors: [JSkinnerUK]
+---
+
+Handle normalisation of some common non-latin diacritic characters, ł, ø, ß, œ.