File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -69,9 +69,15 @@ def better_result(base_result, result = nil)
69
69
end
70
70
71
71
# replacing national prefix to simplified format
72
- def with_replaced_national_prefix ( phone , data )
73
- return phone unless data [ Core ::NATIONAL_PREFIX_TRANSFORM_RULE ]
74
- phone = phone . gsub ( /^#{ data [ Core ::COUNTRY_CODE ] } / , '' ) if phone . start_with? ( data [ Core ::COUNTRY_CODE ] ) && !data [ Core ::DOUBLE_COUNTRY_PREFIX_FLAG ]
72
+ def with_replaced_national_prefix ( passed_phone , data )
73
+ return passed_phone unless data [ Core ::NATIONAL_PREFIX_TRANSFORM_RULE ]
74
+ phone = if passed_phone . start_with? ( data [ Core ::COUNTRY_CODE ] ) && !data [ Core ::DOUBLE_COUNTRY_PREFIX_FLAG ]
75
+ passed_phone . gsub ( /^#{ data [ Core ::COUNTRY_CODE ] } / , '' )
76
+ else
77
+ passed_phone
78
+ end
79
+ return passed_phone unless phone . match? cr ( "^#{ type_regex ( data [ Core ::TYPES ] [ Core ::GENERAL ] , Core ::POSSIBLE_PATTERN ) } $" )
80
+
75
81
pattern = cr ( "^(?:#{ data [ Core ::NATIONAL_PREFIX_FOR_PARSING ] } )" )
76
82
match = phone . match pattern
77
83
if match && match . captures . compact . size > 0
Original file line number Diff line number Diff line change 1428
1428
end
1429
1429
end
1430
1430
1431
+ context 'issue #332' do
1432
+ it 'should parse short number as invalid without replaced prefix' do
1433
+ p = Phonelib . parse ( '+44008123' )
1434
+ expect ( p . valid? ) . to be ( false )
1435
+ end
1436
+ end
1437
+
1431
1438
context 'example numbers' do
1432
1439
it 'are valid' do
1433
1440
data_file = File . dirname ( __FILE__ ) + '/../data/phone_data.dat'
You can’t perform that action at this time.
0 commit comments