Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): export Number Checker numbers without an apostrophe

Yudhi Armyndharis7fce1730d409
diff --git a/dashboard/src/i18n/locales/ar.json b/dashboard/src/i18n/locales/ar.json
index c304a2198..46876f906 100644
--- a/dashboard/src/i18n/locales/ar.json
+++ b/dashboard/src/i18n/locales/ar.json
@@ -1122,6 +1122,7 @@
"start": "بدء الفحص الجماعي",
"stop": "إيقاف الفحص",
"export": "تصدير النتائج (CSV)",
+ "exportHint": "يحتوي الملف على كل الأرقام. قد يعرض برنامج جداول البيانات الأرقام الطويلة بصيغة 9.19612E+11 أو يحذف الصفر البادئ؛ استورد الملف واضبط العمود Phone Number على نص للإبقاء عليها كما هي.",
"stoppedTitle": "توقفت الدفعة",
"checked": "تم فحصها",
"remaining": "المتبقية",
diff --git a/dashboard/src/i18n/locales/de.json b/dashboard/src/i18n/locales/de.json
index 224f4f314..911f3b835 100644
--- a/dashboard/src/i18n/locales/de.json
+++ b/dashboard/src/i18n/locales/de.json
@@ -1093,6 +1093,7 @@
"start": "Batch-Prüfung starten",
"stop": "Prüfung stoppen",
"export": "Ergebnisse exportieren (CSV)",
+ "exportHint": "Die Datei enthält jede Ziffer. Eine Tabellenkalkulation zeigt lange Nummern eventuell als 9.19612E+11 an oder entfernt eine führende Null; importieren Sie die Datei und stellen Sie die Spalte Phone Number auf Text, damit die Nummern unverändert bleiben.",
"stoppedTitle": "Batch gestoppt",
"checked": "Geprüft",
"remaining": "Verbleibend",
diff --git a/dashboard/src/i18n/locales/en.json b/dashboard/src/i18n/locales/en.json
index f39405508..0efc4da85 100644
--- a/dashboard/src/i18n/locales/en.json
+++ b/dashboard/src/i18n/locales/en.json
@@ -1093,6 +1093,7 @@
"start": "Start Batch Check",
"stop": "Stop Checking",
"export": "Export Results (CSV)",
+ "exportHint": "The file holds every digit. A spreadsheet may show long numbers as 9.19612E+11 or drop a leading zero; import the file and set the Phone Number column to Text to keep them as typed.",
"stoppedTitle": "Batch stopped",
"checked": "Checked",
"remaining": "Remaining",
diff --git a/dashboard/src/i18n/locales/es.json b/dashboard/src/i18n/locales/es.json
index 3092c2fec..b96a3f423 100644
--- a/dashboard/src/i18n/locales/es.json
+++ b/dashboard/src/i18n/locales/es.json
@@ -1100,6 +1100,7 @@
"start": "Iniciar verificación por lotes",
"stop": "Detener verificación",
"export": "Exportar resultados (CSV)",
+ "exportHint": "El archivo contiene todos los dígitos. Una hoja de cálculo puede mostrar los números largos como 9.19612E+11 o quitar un cero inicial; importe el archivo y defina la columna Phone Number como Texto para conservarlos tal como están.",
"stoppedTitle": "Lote detenido",
"checked": "Verificados",
"remaining": "Restantes",
diff --git a/dashboard/src/i18n/locales/fr.json b/dashboard/src/i18n/locales/fr.json
index f30229a07..015961055 100644
--- a/dashboard/src/i18n/locales/fr.json
+++ b/dashboard/src/i18n/locales/fr.json
@@ -1100,6 +1100,7 @@
"start": "Démarrer la vérification par lot",
"stop": "Arrêter la vérification",
"export": "Exporter les résultats (CSV)",
+ "exportHint": "Le fichier contient tous les chiffres. Un tableur peut afficher les longs numéros sous la forme 9.19612E+11 ou supprimer un zéro initial ; importez le fichier et réglez la colonne Phone Number sur Texte pour les conserver tels quels.",
"stoppedTitle": "Lot arrêté",
"checked": "Vérifiés",
"remaining": "Restants",
diff --git a/dashboard/src/i18n/locales/he.json b/dashboard/src/i18n/locales/he.json
index 58fa65c16..5633b6399 100644
--- a/dashboard/src/i18n/locales/he.json
+++ b/dashboard/src/i18n/locales/he.json
@@ -1108,6 +1108,7 @@
"start": "התחלת בדיקה מרובה",
"stop": "עצירת הבדיקה",
"export": "ייצוא תוצאות (CSV)",
+ "exportHint": "הקובץ מכיל כל ספרה. גיליון אלקטרוני עשוי להציג מספרים ארוכים כ-9.19612E+11 או להשמיט אפס מוביל; ייבאו את הקובץ והגדירו את העמודה Phone Number כטקסט כדי לשמור אותם כפי שהם.",
"stoppedTitle": "האצווה נעצרה",
"checked": "נבדקו",
"remaining": "נותרו",
diff --git a/dashboard/src/i18n/locales/hi.json b/dashboard/src/i18n/locales/hi.json
index 013c717f6..83ee2a60c 100644
--- a/dashboard/src/i18n/locales/hi.json
+++ b/dashboard/src/i18n/locales/hi.json
@@ -1093,6 +1093,7 @@
"start": "बैच जाँच शुरू करें",
"stop": "जाँच रोकें",
"export": "परिणाम निर्यात करें (CSV)",
+ "exportHint": "फ़ाइल में हर अंक मौजूद है। स्प्रेडशीट लंबे नंबर 9.19612E+11 जैसे दिखा सकती है या शुरुआती शून्य हटा सकती है; नंबर जैसे हैं वैसे रखने के लिए फ़ाइल इंपोर्ट करें और Phone Number कॉलम को टेक्स्ट पर सेट करें।",
"stoppedTitle": "बैच रुक गया",
"checked": "जाँचे गए",
"remaining": "शेष",
diff --git a/dashboard/src/i18n/locales/id.json b/dashboard/src/i18n/locales/id.json
index b3b801625..4e953993c 100644
--- a/dashboard/src/i18n/locales/id.json
+++ b/dashboard/src/i18n/locales/id.json
@@ -1093,6 +1093,7 @@
"start": "Mulai Pemeriksaan Batch",
"stop": "Hentikan Pemeriksaan",
"export": "Ekspor Hasil (CSV)",
+ "exportHint": "File ini memuat semua digit. Aplikasi spreadsheet bisa menampilkan nomor panjang sebagai 9.19612E+11 atau menghapus nol di depan; impor file dan atur kolom Phone Number ke Teks agar nomor tetap utuh.",
"stoppedTitle": "Batch dihentikan",
"checked": "Diperiksa",
"remaining": "Tersisa",
diff --git a/dashboard/src/i18n/locales/it.json b/dashboard/src/i18n/locales/it.json
index 5cb54d570..f0e4ea6ca 100644
--- a/dashboard/src/i18n/locales/it.json
+++ b/dashboard/src/i18n/locales/it.json
@@ -1100,6 +1100,7 @@
"start": "Avvia verifica in blocco",
"stop": "Interrompi verifica",
"export": "Esporta risultati (CSV)",
+ "exportHint": "Il file contiene tutte le cifre. Un foglio di calcolo può mostrare i numeri lunghi come 9.19612E+11 o eliminare uno zero iniziale; importa il file e imposta la colonna Phone Number su Testo per mantenerli così come sono.",
"stoppedTitle": "Verifica in blocco interrotta",
"checked": "Verificati",
"remaining": "Rimanenti",
diff --git a/dashboard/src/i18n/locales/ko.json b/dashboard/src/i18n/locales/ko.json
index 96b2d60a1..def8be777 100644
--- a/dashboard/src/i18n/locales/ko.json
+++ b/dashboard/src/i18n/locales/ko.json
@@ -1093,6 +1093,7 @@
"start": "배치 확인 시작",
"stop": "확인 중지",
"export": "결과 내보내기 (CSV)",
+ "exportHint": "파일에는 모든 숫자가 그대로 들어 있습니다. 스프레드시트는 긴 번호를 9.19612E+11처럼 표시하거나 앞의 0을 지울 수 있습니다. 번호를 그대로 유지하려면 파일을 가져온 뒤 Phone Number 열을 텍스트로 설정하세요.",
"stoppedTitle": "배치 중지됨",
"checked": "확인됨",
"remaining": "남음",
diff --git a/dashboard/src/i18n/locales/pt-BR.json b/dashboard/src/i18n/locales/pt-BR.json
index 290b686e7..165458f8f 100644
--- a/dashboard/src/i18n/locales/pt-BR.json
+++ b/dashboard/src/i18n/locales/pt-BR.json
@@ -1100,6 +1100,7 @@
"start": "Iniciar verificação em lote",
"stop": "Parar verificação",
"export": "Exportar resultados (CSV)",
+ "exportHint": "O arquivo contém todos os dígitos. Uma planilha pode mostrar números longos como 9.19612E+11 ou remover um zero à esquerda; importe o arquivo e defina a coluna Phone Number como Texto para mantê-los como estão.",
"stoppedTitle": "Lote interrompido",
"checked": "Verificados",
"remaining": "Restantes",
diff --git a/dashboard/src/i18n/locales/te.json b/dashboard/src/i18n/locales/te.json
index d0b44fff9..a8137a298 100644
--- a/dashboard/src/i18n/locales/te.json
+++ b/dashboard/src/i18n/locales/te.json
@@ -1093,6 +1093,7 @@
"start": "బ్యాచ్ తనిఖీని ప్రారంభించండి",
"stop": "తనిఖీని ఆపండి",
"export": "ఫలితాలను ఎక్స్‌పోర్ట్ చేయండి (CSV)",
+ "exportHint": "ఫైల్‌లో ప్రతి అంకె ఉంటుంది. స్ప్రెడ్‌షీట్ పొడవైన నంబర్లను 9.19612E+11 లాగా చూపవచ్చు లేదా ముందున్న సున్నాను తీసివేయవచ్చు; నంబర్లను యథాతథంగా ఉంచడానికి ఫైల్‌ను ఇంపోర్ట్ చేసి Phone Number కాలమ్‌ను టెక్స్ట్‌గా సెట్ చేయండి.",
"stoppedTitle": "బ్యాచ్ ఆగిపోయింది",
"checked": "తనిఖీ చేసినవి",
"remaining": "మిగిలినవి",
diff --git a/dashboard/src/i18n/locales/tr.json b/dashboard/src/i18n/locales/tr.json
index 0a5bfe3a4..dc28c8100 100644
--- a/dashboard/src/i18n/locales/tr.json
+++ b/dashboard/src/i18n/locales/tr.json
@@ -1093,6 +1093,7 @@
"start": "Toplu Kontrolü Başlat",
"stop": "Kontrolü Durdur",
"export": "Sonuçları Dışa Aktar (CSV)",
+ "exportHint": "Dosya her rakamı içerir. Bir hesap tablosu uzun numaraları 9.19612E+11 olarak gösterebilir veya baştaki sıfırı silebilir; numaraları olduğu gibi korumak için dosyayı içe aktarın ve Phone Number sütununu Metin olarak ayarlayın.",
"stoppedTitle": "Toplu Kontrol Durduruldu",
"checked": "Kontrol Edilen",
"remaining": "Kalan",
diff --git a/dashboard/src/i18n/locales/zh-CN.json b/dashboard/src/i18n/locales/zh-CN.json
index b7affff74..ae03a361d 100644
--- a/dashboard/src/i18n/locales/zh-CN.json
+++ b/dashboard/src/i18n/locales/zh-CN.json
@@ -1093,6 +1093,7 @@
"start": "开始批量检查",
"stop": "停止检查",
"export": "导出结果(CSV)",
+ "exportHint": "文件包含每一位数字。电子表格可能把长号码显示为 9.19612E+11,或去掉开头的 0;请导入该文件,并将 Phone Number 列设为文本,以保持原样。",
"stoppedTitle": "批量检查已停止",
"checked": "已检查",
"remaining": "剩余",
diff --git a/dashboard/src/i18n/locales/zh-HK.json b/dashboard/src/i18n/locales/zh-HK.json
index 149606f80..9b7146616 100644
--- a/dashboard/src/i18n/locales/zh-HK.json
+++ b/dashboard/src/i18n/locales/zh-HK.json
@@ -1093,6 +1093,7 @@
"start": "開始批量檢查",
"stop": "停止檢查",
"export": "匯出結果(CSV)",
+ "exportHint": "檔案包含每一位數字。試算表可能把長號碼顯示為 9.19612E+11,或去掉開頭的 0;請匯入該檔案,並將 Phone Number 欄設為文字,以保持原樣。",
"stoppedTitle": "批量檢查已停止",
"checked": "已檢查",
"remaining": "剩餘",
diff --git a/dashboard/src/pages/NumberChecker.test.ts b/dashboard/src/pages/NumberChecker.test.ts
index 69127391d..c5778090f 100644
--- a/dashboard/src/pages/NumberChecker.test.ts
+++ b/dashboard/src/pages/NumberChecker.test.ts
@@ -653,8 +653,8 @@ test('NumberChecker: the CSV carries each check as an ISO instant while the tabl
assert.equal(shown, new Date(checkedAt).toLocaleTimeString());
});
-// Opened in a spreadsheet, a bare 919612345678 becomes a number: 9.19612E+11 in a narrow column, and a leading
-// zero is lost. A leading apostrophe makes the cell text, the same prefix that neutralizes a formula.
+// The Phone Number column carries the digits as the gateway answered them: an apostrophe in front would be read
+// literally by Excel and by any program that imports the file.
async function exportedFirstCells(numbers: string, answer: (number: string) => Response, t: TestContext) {
const downloads: Blob[] = [];
t.mock.method(URL, 'createObjectURL', (blob: Blob) => {
@@ -673,16 +673,25 @@ async function exportedFirstCells(numbers: string, answer: (number: string) => R
return rows.map(row => row.split(',')[0]);
}
-test('NumberChecker: the CSV marks each phone number as text, so a spreadsheet keeps its digits', async t => {
+test('NumberChecker: the CSV writes each phone number as bare digits, with no apostrophe', async t => {
const cells = await exportedFirstCells(
'919612345678\n08123456789',
number => jsonResponse({ number, exists: false, whatsappId: null }),
t,
);
- assert.deepEqual(cells, ["'919612345678", "'08123456789"]);
+ assert.deepEqual(cells, ['919612345678', '08123456789']);
});
-test('NumberChecker: a number the gateway echoes as a formula is still neutralized once, not twice', async t => {
+test('NumberChecker: a number typed with a plus is checked and exported as bare digits', async t => {
+ const cells = await exportedFirstCells(
+ '+628123456789',
+ number => jsonResponse({ number, exists: false, whatsappId: null }),
+ t,
+ );
+ assert.deepEqual(cells, ['628123456789']);
+});
+
+test('NumberChecker: a number the gateway echoes as a formula is still neutralized once', async t => {
const cells = await exportedFirstCells(
'919612345678',
() => jsonResponse({ number: '=1+1', exists: false, whatsappId: null }),
@@ -691,6 +700,21 @@ test('NumberChecker: a number the gateway echoes as a formula is still neutraliz
assert.deepEqual(cells, ["'=1+1"]);
});
+test('NumberChecker: the export button is described by a note on how a spreadsheet shows long numbers', async t => {
+ t.mock.method(HTMLAnchorElement.prototype, 'click', () => {});
+ stubLookups(registered);
+ renderComponent();
+ assert.equal(rtl.screen.queryByText(/The file holds every digit/), null);
+ rtl.fireEvent.change(await openBulkTab(), { target: { value: '919612345678' } });
+ startBatch();
+ const button = await rtl.waitFor(() => rtl.screen.getByRole('button', { name: /Export Results/i }), {
+ timeout: 5000,
+ });
+ const note = rtl.screen.getByText(/The file holds every digit.*9\.19612E\+11/);
+ assert.equal(button.getAttribute('aria-describedby'), note.id);
+ assert.notEqual(note.id, '');
+});
+
test('NumberChecker: a rejected lookup is recorded as failed with error status, not as unregistered', async t => {
t.mock.method(HTMLAnchorElement.prototype, 'click', () => {});
const recordedDownloads: Blob[] = [];
diff --git a/dashboard/src/pages/NumberChecker.tsx b/dashboard/src/pages/NumberChecker.tsx
index a81325ee8..de780b316 100644
--- a/dashboard/src/pages/NumberChecker.tsx
+++ b/dashboard/src/pages/NumberChecker.tsx
@@ -248,10 +248,7 @@ export function NumberChecker() {
const rows = batchResults
.map(r => {
const hasWa = r.status === 'failed' ? 'Error' : r.exists ? 'Yes' : 'No';
- // A leading apostrophe keeps a spreadsheet from turning the digits into a number (9.19612E+11, lost
- // leading zero). It is the prefix escapeCsvCell adds to neutralize a formula, so a number that is not
- // digits comes out with the one apostrophe, not two.
- return [`'${r.number}`, hasWa, r.whatsappId, r.error, r.timestamp].map(escapeCsvCell).join(',');
+ return [r.number, hasWa, r.whatsappId, r.error, r.timestamp].map(escapeCsvCell).join(',');
})
.join('\n');
const blob = new Blob([header + rows], { type: 'text/csv;charset=utf-8;' });
@@ -728,9 +725,14 @@ export function NumberChecker() {
)}
{batchResults.length > 0 && !isCheckingBatch && (
- <button className="nc-btn nc-btn-secondary" onClick={handleExportCSV}>
- <Download size={18} /> {t('numberChecker.bulk.export')}
- </button>
+ <>
+ <button className="nc-btn nc-btn-secondary" onClick={handleExportCSV} aria-describedby="nc-export-hint">
+ <Download size={18} /> {t('numberChecker.bulk.export')}
+ </button>
+ <span id="nc-export-hint" className="nc-hint" style={{ flexBasis: '100%', margin: 0 }}>
+ {t('numberChecker.bulk.exportHint')}
+ </span>
+ </>
)}
</div>
diff --git a/dashboard/src/utils/csv.test.ts b/dashboard/src/utils/csv.test.ts
index b0f180e67..3821de579 100644
--- a/dashboard/src/utils/csv.test.ts
+++ b/dashboard/src/utils/csv.test.ts
@@ -44,3 +44,12 @@ test('cells starting with a tab or carriage return are apostrophe-prefixed', ()
assert.equal(escapeCsvCell('\t=1+1'), `'\t=1+1`);
assert.equal(escapeCsvCell('\r=1'), `"'\r=1"`);
});
+
+test('a bare run of digits is written as is, so a reader gets the number itself', () => {
+ assert.equal(escapeCsvCell('919612345678'), '919612345678');
+ assert.equal(escapeCsvCell('08123456789'), '08123456789');
+});
+
+test('a number that starts with a plus is neutralized like any other formula start', () => {
+ assert.equal(escapeCsvCell('+628123456789'), `'+628123456789`);
+});
diff --git a/dashboard/src/utils/csv.ts b/dashboard/src/utils/csv.ts
index 3d8b47e3e..9f62b8f7c 100644
--- a/dashboard/src/utils/csv.ts
+++ b/dashboard/src/utils/csv.ts
@@ -1,5 +1,5 @@
/**
- * Escape one CSV cell for the audit-log export.
+ * Escape one CSV cell for the audit-log and Number Checker exports.
*
* Two concerns, in order:
* 1. Formula injection: a cell whose text begins with `=`, `+`, `-`, `@`, a tab or a carriage
@@ -7,8 +7,8 @@
* (Excel/LibreOffice/Sheets). Audit rows carry attacker-influenced strings (request paths,
* error messages, API-key names), so a logged request like `GET /=HYPERLINK("https://evil…")`
* would become a live formula in the operator's spreadsheet. Neutralize by prefixing an
- * apostrophe: the spreadsheet then shows the value as text. This mangles the export only (the
- * dashboard UI shows the raw value).
+ * apostrophe: the spreadsheet then reads the value as text, and in a CSV file Excel shows the
+ * apostrophe itself. This mangles the export only (the dashboard UI shows the raw value).
* 2. Structural quoting (pre-existing rule): a value containing `"`, `,`, a newline or a carriage
* return is wrapped in double quotes with inner quotes doubled.
*/