diff --git a/app/services/whatsapp/phone_normalizers/brazil_phone_normalizer.rb b/app/services/whatsapp/phone_normalizers/brazil_phone_normalizer.rb index be246f330..089fa7ba8 100644 --- a/app/services/whatsapp/phone_normalizers/brazil_phone_normalizer.rb +++ b/app/services/whatsapp/phone_normalizers/brazil_phone_normalizer.rb @@ -14,7 +14,7 @@ class Whatsapp::PhoneNormalizers::BrazilPhoneNormalizer < Whatsapp::PhoneNormali return waid unless handles_country?(waid) ddd = waid[COUNTRY_CODE_LENGTH, DDD_LENGTH] - number = waid[COUNTRY_CODE_LENGTH + DDD_LENGTH, waid.length - (COUNTRY_CODE_LENGTH + DDD_LENGTH)] + number = waid[(COUNTRY_CODE_LENGTH + DDD_LENGTH)..].to_s return waid unless number.match?(LEGACY_MOBILE_NUMBER_PATTERN) "55#{ddd}9#{number}" diff --git a/app/services/whatsapp/phone_number_normalization_service.rb b/app/services/whatsapp/phone_number_normalization_service.rb index 02e4fe7ac..2f49cc810 100644 --- a/app/services/whatsapp/phone_number_normalization_service.rb +++ b/app/services/whatsapp/phone_number_normalization_service.rb @@ -29,15 +29,6 @@ class Whatsapp::PhoneNumberNormalizationService existing_contact_inbox&.source_id || raw_number end - # @param clean_number [String] Phone number in clean cloud format, e.g. "5541988887777" - # @return [String] Country-normalized number, or the original when no normalizer applies - def normalize_number(clean_number) - normalizer = find_normalizer_for_country(clean_number) - return clean_number unless normalizer - - normalizer.normalize(clean_number) - end - # Keep the provider value first so exact contact matches always win. Each # country normalizer explicitly opts into contact-safe alternatives; source-id # normalization alone is not enough because the alternate may be another diff --git a/spec/services/whatsapp/phone_normalizers/brazil_phone_normalizer_spec.rb b/spec/services/whatsapp/phone_normalizers/brazil_phone_normalizer_spec.rb new file mode 100644 index 000000000..373b7f70e --- /dev/null +++ b/spec/services/whatsapp/phone_normalizers/brazil_phone_normalizer_spec.rb @@ -0,0 +1,9 @@ +require 'rails_helper' + +describe Whatsapp::PhoneNormalizers::BrazilPhoneNormalizer do + describe '#contact_candidates' do + it 'preserves a partial Brazil number without raising' do + expect(described_class.new.contact_candidates('55')).to eq(['55']) + end + end +end