phony 2.19.15 → 2.20.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45ec2d2d9ab9772ae3f05cd031cd6d4214f1a541838ac8539e5a8d60039d5119
4
- data.tar.gz: 4998f527b3b6e2414ef7411c9736a39eaf4b9639faaca8d604a9802b1cf24d5b
3
+ metadata.gz: 53e35e946aea7db6e2c7901a5df43de446fc04289fa976f4d2d655a09f4bdbae
4
+ data.tar.gz: f7f0cb0e4ee68d31a754d2c57fcde82116907fced053416c630eafcf71e8cd12
5
5
  SHA512:
6
- metadata.gz: 8fc13c0c16a9dd41bc947308ca2e0c36d59f4efce442c9d21a105aeb919ce323e8190ee0e302cd184e7145b26d6f3b3c9c42009ed6905240c7884fba98b98918
7
- data.tar.gz: 5cdc031002c1e727a852b67897d93e3c93c3aef931f1f9a563f62d0b37af9eb137a8e81b37648b57d05f1466e8bebcf0b175cba71215b4c97d7dc80fa78a5bdc
6
+ metadata.gz: 4e43b987e4313294e70a389da3441e364c8c0cd4930344c2beaadaef58cc60afdf3fc8f265e75923968f8dba565988237067375d41f9546f1dae1c9d258c6aa3
7
+ data.tar.gz: b3d7ba6dd615c1d36be9b284da5a578c1f8d11937230bf73185f172250c74d17ffb5a00fe2002f787731c2970587c3e19c1be012469227f28763563389c2da95
@@ -100,6 +100,17 @@ module Phony
100
100
  return false unless (4..16) === normalized.size # unless hints[:check_length] == false
101
101
 
102
102
  country, cc, rest = partial_split normalized
103
+
104
+ # Was a country calling code given?
105
+ #
106
+ if ccc = hints[:ccc]
107
+ cc, ndc, *local = split ccc
108
+
109
+ raise ArgumentError.new("The provided ccc option is too long and includes more than a cc ('#{cc}') and ndc ('#{ndc}'). It also includes '#{local.join}'.") unless local.size == 1 && local[0].empty?
110
+
111
+ hints[:cc] = cc
112
+ hints[:ndc] = ndc
113
+ end
103
114
 
104
115
  # Country code plausible?
105
116
  #
@@ -109,6 +120,8 @@ module Phony
109
120
  # Country specific tests.
110
121
  #
111
122
  country.plausible? rest, hints
123
+ rescue ArgumentError
124
+ raise
112
125
  rescue StandardError
113
126
  return false
114
127
  end
@@ -4,6 +4,27 @@ describe Phony::CountryCodes do
4
4
 
5
5
  let(:countries) { Phony::CountryCodes.instance }
6
6
 
7
+ describe '#plausible?' do
8
+ it 'raises an error on a too long ccc' do
9
+ expect do
10
+ countries.plausible?('+1 868 7620266', ccc: '1868123')
11
+ end.to raise_error(ArgumentError, %Q{The provided ccc option is too long and includes more than a cc ('1') and ndc ('868'). It also includes '123'.})
12
+ end
13
+ end
14
+
15
+ describe 'ccc handling' do
16
+ it 'splits a ccc correctly' do
17
+ cc, ndc, *local = countries.split('1868')
18
+ cc.should eq('1')
19
+ ndc.should eq('868')
20
+ end
21
+ it 'splits a ccc correctly' do
22
+ cc, ndc, *local = countries.split('1868')
23
+ cc.should eq('1')
24
+ ndc.should eq('868')
25
+ end
26
+ end
27
+
7
28
  describe '#[]' do
8
29
  it 'returns a country' do
9
30
  countries['41'].class.should eql Phony::Country
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phony
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.19.15
4
+ version: 2.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Hanke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-27 00:00:00.000000000 Z
11
+ date: 2022-07-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'Fast international phone number (E164 standard) normalizing, splitting
14
14
  and formatting. Lots of formatting options: International (+.., 00..), national