Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): split bulk recipients on CR line endings

Yudhi Armyndharis5f1e2eb9fab7
diff --git a/dashboard/src/utils/bulkRecipients.test.ts b/dashboard/src/utils/bulkRecipients.test.ts
index 8c5dd07d3..224d0cec3 100644
--- a/dashboard/src/utils/bulkRecipients.test.ts
+++ b/dashboard/src/utils/bulkRecipients.test.ts
@@ -15,6 +15,12 @@ test('passes full chat IDs through untouched', () => {
assert.deepEqual(parseBulkRecipients('123@lid\[email protected]'), ['123@lid', '[email protected]']);
});
+test('splits on CRLF and on bare CR, which an uploaded file can carry', () => {
+ const expected = ['[email protected]', '[email protected]'];
+ assert.deepEqual(parseBulkRecipients('628111222333\r\n628222333444'), expected);
+ assert.deepEqual(parseBulkRecipients('628111222333\r628222333444'), expected);
+});
+
test('de-dupes entries that normalize to the same chat ID', () => {
const text = '+62 812 3456 78\n62812345678\[email protected]';
assert.deepEqual(parseBulkRecipients(text), ['[email protected]']);
diff --git a/dashboard/src/utils/bulkRecipients.ts b/dashboard/src/utils/bulkRecipients.ts
index 245fd1394..9d44fd211 100644
--- a/dashboard/src/utils/bulkRecipients.ts
+++ b/dashboard/src/utils/bulkRecipients.ts
@@ -6,10 +6,14 @@ export const BULK_MAX_RECIPIENTS = 100;
* drops blank lines, de-dupes, and normalizes bare phone numbers to `<digits>@c.us`. Lines
* containing '@' are treated as full chat IDs and pass through untouched; lines with no '@'
* and no digits at all are dropped rather than sent as the meaningless '@c.us'.
+ *
+ * All three line endings are accepted. A textarea normalizes CR and CRLF to LF in its own value, but
+ * an uploaded file does not go through one: FileReader hands the bytes over as written, so a file
+ * saved with classic Mac endings arrives as a single bare-CR line.
*/
export function parseBulkRecipients(text: string): string[] {
const seen = new Set<string>();
- for (const rawLine of text.split('\n')) {
+ for (const rawLine of text.split(/\r\n?|\n/)) {
const line = rawLine.trim();
if (!line) continue;
if (line.includes('@')) {