Skip to content

Commit

Permalink
fixed issue #309
Browse files Browse the repository at this point in the history
  • Loading branch information
daddyz committed Sep 8, 2024
1 parent 466a328 commit 504ed6c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/phonelib/data_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def import_country_names
# adds double country code flag in case country allows
def add_double_country_flag(country)
if DOUBLE_COUNTRY_CODES_COUNTRIES.include?(country[:id])
country[:double_prefix] = true
country[Core::DOUBLE_COUNTRY_PREFIX_FLAG] = true
end
country
end
Expand Down
2 changes: 1 addition & 1 deletion lib/phonelib/phone_analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def better_result(base_result, result = nil)
# replacing national prefix to simplified format
def with_replaced_national_prefix(phone, data)
return phone unless data[Core::NATIONAL_PREFIX_TRANSFORM_RULE]
phone = phone.gsub(/^#{data[Core::COUNTRY_CODE]}/, '') if phone.start_with?(data[Core::COUNTRY_CODE])
phone = phone.gsub(/^#{data[Core::COUNTRY_CODE]}/, '') if phone.start_with?(data[Core::COUNTRY_CODE]) && !data[Core::DOUBLE_COUNTRY_PREFIX_FLAG]
pattern = cr("^(?:#{data[Core::NATIONAL_PREFIX_FOR_PARSING]})")
match = phone.match pattern
if match && match.captures.compact.size > 0
Expand Down
9 changes: 9 additions & 0 deletions spec/phonelib_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,15 @@
end
end

context 'issue #309' do
it 'should return same result without specifying country' do
p1 = Phonelib.parse('+55 55 96722 8964', 'BR')
p2 = Phonelib.parse('+55 55 96722 8964')
expect(p1.valid?).to be(p2.valid?)
expect(p1.international).to eq(p2.international)
end
end

context 'example numbers' do
it 'are valid' do
data_file = File.dirname(__FILE__) + '/../data/phone_data.dat'
Expand Down

0 comments on commit 504ed6c

Please sign in to comment.