From 82563a7651872d08e2e1064afa6d846a4cc9aecc Mon Sep 17 00:00:00 2001 From: Hugo Montenegro Date: Wed, 17 Jun 2026 13:36:42 -0700 Subject: [PATCH] fix(pix): canonicalize +55 phone keys that already carry a + prefix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit normalizePixPhoneNumber returned the raw input untouched when the cleaned value already started with '+', so '+55-11-99999-9999' kept its separators and stayed non-canonical — conflicting with the helper's contract and risking PIX-key mismatches. Always return the separator-free +55 form. From release-PR #2236 CodeRabbit triage; adds the separator-with-+ regression cases the existing +-prefix tests never exercised. --- src/utils/__tests__/withdraw.utils.test.ts | 3 +++ src/utils/withdraw.utils.ts | 9 +++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/utils/__tests__/withdraw.utils.test.ts b/src/utils/__tests__/withdraw.utils.test.ts index 5da97f3f4..da08bd091 100644 --- a/src/utils/__tests__/withdraw.utils.test.ts +++ b/src/utils/__tests__/withdraw.utils.test.ts @@ -79,6 +79,9 @@ describe('Withdraw Utilities', () => { // Should keep existing + prefix ['+5511999999999', '+5511999999999'], ['+551199999999', '+551199999999'], + // Should strip separators even when the + prefix is already present + ['+55-11-99999-9999', '+5511999999999'], + ['+55 11 99999 9999', '+5511999999999'], // Should not modify non-phone formats ['12345678901', '12345678901'], // CPF ['12345678901234', '12345678901234'], // CNPJ diff --git a/src/utils/withdraw.utils.ts b/src/utils/withdraw.utils.ts index 9130416c6..bde51d4dc 100644 --- a/src/utils/withdraw.utils.ts +++ b/src/utils/withdraw.utils.ts @@ -212,10 +212,11 @@ export const isPixPhoneNumber = (pixKey: string): boolean => { */ export const normalizePixPhoneNumber = (pixKey: string): string => { const cleaned = pixKey.replace(/[\s-]/g, '') - if (isPixPhoneNumber(cleaned) && !cleaned.startsWith('+')) { - return '+' + cleaned - } - return pixKey + if (!isPixPhoneNumber(cleaned)) return pixKey + // Always return the separator-free +55 form. The old code returned the raw + // input untouched when it already started with '+', so inputs like + // '+55-11-99999-9999' kept their separators and stayed non-canonical. + return cleaned.startsWith('+') ? cleaned : '+' + cleaned } /**