Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): split a bulk list written in another script

Yudhi Armyndhariscea66524c8b2
diff --git a/dashboard/src/utils/bulkRecipients.test.ts b/dashboard/src/utils/bulkRecipients.test.ts
index 2f01870ae..f03ee2db3 100644
--- a/dashboard/src/utils/bulkRecipients.test.ts
+++ b/dashboard/src/utils/bulkRecipients.test.ts
@@ -86,3 +86,28 @@ test('a number written in native-script or full-width digits is read as ASCII di
]);
});
+
+// The same separators the Number Checker splits its list on, in the script the numbers are written in.
+test('a list in native-script digits separated by the Arabic comma or semicolon is several recipients', () => {
+ const toDigits = (ascii: string) => [...ascii].map(d => String.fromCharCode(0x0660 + Number(d))).join('');
+ const first = toDigits('628123456789');
+ const second = toDigits('628987654321');
+ const expected = ['[email protected]', '[email protected]'];
+ assert.deepEqual(parseBulkRecipients(`${first}${String.fromCharCode(0x060c)}${second}`), expected);
+ assert.deepEqual(parseBulkRecipients(`${first}${String.fromCharCode(0x061b)} ${second}`), expected);
+});
+
+test('a list in full-width digits separated by the full-width comma or semicolon is several recipients', () => {
+ const fullwidth = (ascii: string) => [...ascii].map(ch => String.fromCharCode(ch.charCodeAt(0) + 0xfee0)).join('');
+ const first = fullwidth('628123456789');
+ const second = fullwidth('628987654321');
+ const expected = ['[email protected]', '[email protected]'];
+ assert.deepEqual(parseBulkRecipients(`${first}${String.fromCharCode(0xff0c)}${second}`), expected);
+ assert.deepEqual(parseBulkRecipients(`${first}${String.fromCharCode(0xff1b)}${second}`), expected);
+});
+
+test('a chat id written in full-width characters passes through as the plain chat id', () => {
+ const fullwidth = (ascii: string) => [...ascii].map(ch => String.fromCharCode(ch.charCodeAt(0) + 0xfee0)).join('');
+ assert.deepEqual(parseBulkRecipients(fullwidth('[email protected]')), ['[email protected]']);
+ assert.deepEqual(parseBulkRecipients(fullwidth('[email protected]')), []);
+});
diff --git a/dashboard/src/utils/bulkRecipients.ts b/dashboard/src/utils/bulkRecipients.ts
index 963f947a8..b26f5eb98 100644
--- a/dashboard/src/utils/bulkRecipients.ts
+++ b/dashboard/src/utils/bulkRecipients.ts
@@ -25,11 +25,12 @@ export const BULK_RECIPIENTS_FILE_MAX_BYTES = 2 * 1024 * 1024;
* saved with classic Mac endings arrives as a single bare-CR line.
*/
/**
- * Field separators a spreadsheet export uses. Deliberately NOT space, parentheses or hyphen: those
+ * Field separators a spreadsheet export uses, and the Arabic comma and semicolon (the full-width ones are folded to
+ * these ASCII ones before the split). Deliberately NOT space, parentheses or hyphen: those
* are phone-number formatting (`+1 (555) 010-2233` is one entry, not five), and no WhatsApp chat id
* shape contains a comma, a semicolon or a tab.
*/
-const FIELD_SEPARATORS = /[,;\t]/;
+const FIELD_SEPARATORS = /[,;\t\u060C\u061B]/;
/**
* Fewest digits a bare number may carry to be treated as a phone number, matching the bound the
@@ -49,7 +50,8 @@ const CHAT_ID = /^[0-9][0-9:-]*@(c\.us|g\.us|s\.whatsapp\.net|lid|newsletter|bro
export function parseBulkRecipients(text: string): string[] {
const seen = new Set<string>();
- for (const rawLine of text.split(/\r\n?|\n/)) {
+ // Folded before the split, so a list in the digits and the commas of another script is split as it reads.
+ for (const rawLine of normalizePhoneText(text).split(/\r\n?|\n/)) {
// Split into fields before anything else. The button offers `.csv`, and a row with more than one
// column used to have its columns' digits CONCATENATED by the strip below: `1,628123456789`
// became `[email protected]`, a different number that looks entirely plausible in the
@@ -61,7 +63,7 @@ export function parseBulkRecipients(text: string): string[] {
if (CHAT_ID.test(field)) seen.add(field);
continue;
}
- const digits = normalizePhoneText(field).replace(/[^0-9]/g, '');
+ const digits = field.replace(/[^0-9]/g, '');
if (digits.length >= MIN_PHONE_DIGITS) seen.add(`${digits}@c.us`);
}
}