Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): read native-script digits in Number Checker

Yudhi Armyndharisceb2cf7593f4
diff --git a/dashboard/src/pages/NumberChecker.test.ts b/dashboard/src/pages/NumberChecker.test.ts
index ec966142b..ebba3f755 100644
--- a/dashboard/src/pages/NumberChecker.test.ts
+++ b/dashboard/src/pages/NumberChecker.test.ts
@@ -177,6 +177,43 @@ test('NumberChecker: bulk parsing deduplicates explicit international numbers wi
assert.deepEqual(lookups, ['6581234567']);
});
+// A number typed or pasted with another script's decimal digits is the same number: it reaches the gateway in ASCII.
+const toDigits = (ascii: string, zero: number) => [...ascii].map(d => String.fromCharCode(zero + Number(d))).join('');
+const DIGIT_SCRIPTS = [
+ ['Arabic-Indic', 0x0660],
+ ['Persian', 0x06f0],
+ ['Devanagari', 0x0966],
+ ['Telugu', 0x0c66],
+ ['full-width', 0xff10],
+] as const;
+
+for (const [script, zero] of DIGIT_SCRIPTS) {
+ test(`NumberChecker: ${script} digits are previewed and looked up as ASCII digits`, async () => {
+ const lookups = stubLookups(registered);
+ const { container } = renderComponent();
+ await rtl.screen.findByRole('option', { name: /Primary Session/ });
+ rtl.fireEvent.change(rtl.screen.getByPlaceholderText(/9876543210/), {
+ target: { value: toDigits('6281234567891', zero) },
+ });
+ assert.match(container.querySelector('.nc-format-preview')?.textContent ?? '', /\+6281234567891 \(13 digits\)/);
+ rtl.fireEvent.click(rtl.screen.getByRole('button', { name: 'Check' }));
+ await rtl.screen.findByText('Registered', { selector: '.nc-status-badge' });
+ assert.deepEqual(lookups, ['6281234567891']);
+ });
+}
+
+test('NumberChecker: a bulk list in several scripts is parsed and deduplicated as ASCII numbers', async () => {
+ const lookups = stubLookups(registered);
+ renderComponent();
+ const textarea = await openBulkTab();
+ const list = [toDigits('6281234567891', 0x0660), toDigits('6281234567892', 0xff10), '6281234567891'].join('\n');
+ rtl.fireEvent.change(textarea, { target: { value: list } });
+ assert.match(rtl.screen.getByText(/unique numbers parsed/).textContent ?? '', /\b2 unique numbers parsed$/);
+ startBatch();
+ await rtl.screen.findByText('Completed checking 2 numbers.', {}, { timeout: 3000 });
+ assert.deepEqual(lookups, ['6281234567891', '6281234567892']);
+});
+
test('NumberChecker: bulk parsing also splits on the Arabic comma and semicolon', async () => {
stubLookups(registered);
renderComponent();
diff --git a/dashboard/src/pages/NumberChecker.tsx b/dashboard/src/pages/NumberChecker.tsx
index d4c63ae69..f753b3bc9 100644
--- a/dashboard/src/pages/NumberChecker.tsx
+++ b/dashboard/src/pages/NumberChecker.tsx
@@ -79,6 +79,19 @@ export interface CheckResultItem extends CheckNumberResponse {
const timeOfDay = (iso: string) => new Date(iso).toLocaleTimeString();
+// Unicode keeps every script's decimal digits in an unbroken run that starts at its zero.
+function asciiDigit(digit: string): string {
+ const code = digit.codePointAt(0)!;
+ let zero = code;
+ while (/\p{Nd}/u.test(String.fromCodePoint(zero - 1))) zero--;
+ return String((code - zero) % 10);
+}
+
+// The text as typed or pasted, with every script's decimal digits as ASCII ones.
+function normalizePhoneText(text: string): string {
+ return text.replace(/\p{Nd}/gu, asciiDigit);
+}
+
export function NumberChecker() {
const { t } = useTranslation();
useDocumentTitle(t('nav.numberChecker'));
@@ -127,7 +140,8 @@ export function NumberChecker() {
// Format and clean phone number based on digit rules
const formatNumberForCheck = useCallback(
- (raw: string, applyPrefix = autoPrefix91) => {
+ (typed: string, applyPrefix = autoPrefix91) => {
+ const raw = normalizePhoneText(typed);
let digits = raw.replace(/[^0-9]/g, '');
const isInternational = raw.trim().startsWith('+') || digits.startsWith('00');
// 1. If international dial exit code 00 is present (e.g. 009196...), strip '00'
@@ -159,7 +173,7 @@ export function NumberChecker() {
// Batch parsing statistics
const batchParsedStats = useMemo(() => {
- const lines = batchInput
+ const lines = normalizePhoneText(batchInput)
.split(/[\n,;\u060C\u061B]+/)
.map(n => n.trim())
.filter(n => n.length > 0);