[core] Fix BR landline normalization in PhoneJidNormalizer (#1976)
Prevent unconditional insertion of digit 9 for Brazilian numbers with 8-digit local parts by preserving landline patterns (2..5) and keeping add-9 behavior for mobile/other cases. fix #1974
This commit is contained in:
1 parent
03e9588581
commit
e64b60ef3a
2 files changed
+18
-17
No files matched your search
@@ -20,25 +20,18 @@ describe('E164Parser.fromJid', () => {
|
||||
expect(E164Parser.fromJid('@s.whatsapp.net')).toBeNull();
|
||||
});
|
||||
|
||||
it('applies Brazil add-9 rule when local has 8 digits (any first digit)', () => {
|
||||
// +55 <DDD:2> <local:8>
|
||||
expect(E164Parser.fromJid('553188888888@s.whatsapp.net')).toBe(
|
||||
'+5531988888888',
|
||||
it('does not add 9 for BR landline (local starts with 2..5)', () => {
|
||||
expect(E164Parser.fromJid('558540423147@s.whatsapp.net')).toBe(
|
||||
'+558540423147',
|
||||
);
|
||||
expect(E164Parser.fromJid('558820181896@s.whatsapp.net')).toBe(
|
||||
'+558820181896',
|
||||
);
|
||||
});
|
||||
|
||||
it('554999111111 => 5549999111111', () => {
|
||||
expect(E164Parser.fromJid('554999111111@s.whatsapp.net')).toBe(
|
||||
'+5549999111111',
|
||||
);
|
||||
});
|
||||
|
||||
it('adds 9 even when local already starts with 9 (Brazil)', () => {
|
||||
expect(E164Parser.fromJid('553198888888@s.whatsapp.net')).toBe(
|
||||
'+5531998888888',
|
||||
);
|
||||
expect(E164Parser.fromJid('553199999999@s.whatsapp.net')).toBe(
|
||||
'+5531999999999',
|
||||
it('adds 9 for BR mobile/others (local not starting with 2..5)', () => {
|
||||
expect(E164Parser.fromJid('558591203123@s.whatsapp.net')).toBe(
|
||||
'+5585991203123',
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -56,7 +56,15 @@ export class PhoneJidNormalizer {
|
||||
}
|
||||
|
||||
const RULES = [
|
||||
// Brazil - ensure mobile numbers have 9 digits after DDD
|
||||
// Brazil landline (fixed line) heuristic:
|
||||
// +55 <DDD:2> <local:8> where local[0] is 2..5 => do NOT add extra 9
|
||||
{
|
||||
name: 'br-no-add-9-for-landline',
|
||||
re: /^\+55(\d{2})([2-5]\d{7})$/,
|
||||
replace: '+55$1$2',
|
||||
},
|
||||
// Brazil mobile/others:
|
||||
// +55 <DDD:2> <local:8> => add extra 9 after DDD
|
||||
{
|
||||
name: 'br-add-9-after-ddd',
|
||||
re: /^\+55(\d{2})(\d{8})$/,
|
||||
|
||||
Reference in new issue
Block a user