fix: commerzbank escape payee (#4845)

This commit is contained in:
Michael Süssemilch
2025-04-21 14:28:27 +02:00
committed by GitHub
parent f5c1879de1
commit b92a1cacf7
4 changed files with 37 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
import Fallback from './integration-bank.js';
import { escapeRegExp } from './util/escape-regexp.js';
/** @type {import('./bank.interface.js').IBank} */
export default {
@@ -38,7 +39,9 @@ export default {
// Clean up remittanceInformation, deduplicate payee (removing slashes ...
// ... that are added to the remittanceInformation field), and ...
// ... remove clutter like "End-to-End-Ref.: NOTPROVIDED"
const payee = transaction.creditorName || transaction.debtorName || '';
const payee = escapeRegExp(
transaction.creditorName || transaction.debtorName || '',
);
editedTrans.remittanceInformationUnstructured =
editedTrans.remittanceInformationUnstructured
.replace(/\s*(,)?\s+/g, '$1 ')

View File

@@ -106,5 +106,28 @@ describe('CommerzbankCobadeff', () => {
'CREDITOR00BIC CREDITOR000IBAN DESCRIPTION, Dauerauftrag',
);
});
it('correctly uses regex on payee with special characters', () => {
const transaction = {
endToEndId: '1234567890',
mandateId: '1234567890',
bookingDate: '2025-04-18',
valueDate: '2025-04-18',
transactionAmount: {
amount: '-1',
currency: 'EUR',
},
creditorName: 'Netto Marken-Discount Halle (Saale',
remittanceInformationUnstructured: 'Example',
remittanceInformationUnstructuredArray: ['Example'],
remittanceInformationStructured: 'Example',
// internalTransactionId: '3815213adb654baeadfb231c853',
};
const normalizedTransaction = CommerzbankCobadeff.normalizeTransaction(
transaction,
false,
);
expect(normalizedTransaction.notes).toEqual('Example');
});
});
});

View File

@@ -0,0 +1,4 @@
// Escape special characters in the string to create a valid regular expression
export function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}

View File

@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [misu-dev]
---
Escape Payee for Commerzbank RegExp