validates_zipcode 0.5.3 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e698716ffc57c2d3fcdbfcda2dea3817842ed64b10c7739709a7cdad8914789a
|
|
4
|
+
data.tar.gz: a50c8edeeadf3aa499d92260214fd65cc6e2bb1ed34f866133eb5480ecb89d5c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b50f55f7f3265cf5de4f56292cc4167cd860afa19e28752b830238bb9e622fdf6948f7da0c60dc5d004524a7595029e8cd45da272deb8978c98bf7be080737a6
|
|
7
|
+
data.tar.gz: 7750e6f341ca45e65cfa0c5fde71e2b5c451fe99a7fa910cfd6c6ab33695864baef875c041587fe5d451b32e8700cc8147bf54b2a75ef796e489e6c2abac8706
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
## Unreleased
|
|
6
6
|
|
|
7
|
+
## 0.6.0
|
|
8
|
+
|
|
9
|
+
**Heads up:** This release changes the behaviour of `ValidatesZipcode.valid?` when an unknown or malformed country code is passed. Previously, passing a country code not recognised by the gem (e.g. `'UKXXXXX'`) would return `true` — no regex to match against meant no failure. It will now return `false`.
|
|
10
|
+
|
|
11
|
+
If you were relying on the old behaviour (passing arbitrary country codes and expecting `true`), this is a breaking change for those cases. For everyone else, this is the expected fix — an unrecognised country is not a valid one.
|
|
12
|
+
|
|
13
|
+
- Return `false` when the country code is not a known ISO 3166-1 alpha-2 code, instead of silently returning `true` — fixes #67
|
|
14
|
+
|
|
7
15
|
## 0.5.3
|
|
8
16
|
|
|
9
17
|
- See commits up to 4e5a3132061d57d220d1616beb15d15a47d301df
|
|
@@ -80,7 +80,7 @@ module ValidatesZipcode
|
|
|
80
80
|
NG: /\A\d{6}\z/,
|
|
81
81
|
OM: /\A(PC )?\d{3}\z/i,
|
|
82
82
|
PK: /\A\d{5}\z/,
|
|
83
|
-
PY: /\A\d{4}\z/,
|
|
83
|
+
PY: /\A(\d{4}|\d{6})\z/,
|
|
84
84
|
PH: /\A\d{4}\z/,
|
|
85
85
|
PL: /\A\d{2}[ -]?\d{3}\z/,
|
|
86
86
|
PR: /\A00[679]\d{2}([ \-]\d{4})?\z/,
|
|
@@ -154,7 +154,7 @@ module ValidatesZipcode
|
|
|
154
154
|
BI: /\A([A-Z\d\s]){3,}\z/i,
|
|
155
155
|
BS: /\A([A-Z\d\s]){3,}\z/i,
|
|
156
156
|
BZ: /\A([A-Z\d\s]){3,}\z/i,
|
|
157
|
-
BR: /\A\d{5}(-?\d{3})
|
|
157
|
+
BR: /\A\d{5}(-?\d{3})\z/,
|
|
158
158
|
BJ: /\A([A-Z\d\s]){3,}\z/i,
|
|
159
159
|
BT: /\A\d{5}\z/,
|
|
160
160
|
BQ: /\A([A-Z\d\s]){3,}\z/i,
|
|
@@ -12,6 +12,7 @@ module ValidatesZipcode
|
|
|
12
12
|
|
|
13
13
|
def valid?
|
|
14
14
|
return true if @excluded_country_codes.include?(@country_alpha2)
|
|
15
|
+
return false unless valid_country_alpha2?
|
|
15
16
|
return true unless regexp
|
|
16
17
|
|
|
17
18
|
zipcode = @format ? formatted_zip : @zipcode
|
|
@@ -31,6 +32,13 @@ module ValidatesZipcode
|
|
|
31
32
|
@regexp ||= regexp_for_country_alpha2(@country_alpha2)
|
|
32
33
|
end
|
|
33
34
|
|
|
35
|
+
# ISO 3166-1 alpha-2 codes are exactly 2 uppercase ASCII letters.
|
|
36
|
+
# Anything longer or shorter (e.g. "UKXXXXX", "G", "12") is not a
|
|
37
|
+
# valid country code and should fail validation immediately.
|
|
38
|
+
def valid_country_alpha2?
|
|
39
|
+
@country_alpha2.to_s.match?(/\A[A-Za-z]{2}\z/)
|
|
40
|
+
end
|
|
41
|
+
|
|
34
42
|
def formatted_zip
|
|
35
43
|
@formatted_zip ||= Formatter.new(zipcode: @zipcode, country_alpha2: @country_alpha2).format
|
|
36
44
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -554,9 +554,9 @@ TEST_DATA = {
|
|
|
554
554
|
},
|
|
555
555
|
KH: {
|
|
556
556
|
valid: %w[
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
557
|
+
071131
|
|
558
|
+
025662
|
|
559
|
+
662613
|
|
560
560
|
],
|
|
561
561
|
invalid: [
|
|
562
562
|
nil,
|
|
@@ -1117,6 +1117,7 @@ TEST_DATA = {
|
|
|
1117
1117
|
2566
|
|
1118
1118
|
6261
|
|
1119
1119
|
7113
|
|
1120
|
+
111421
|
|
1120
1121
|
],
|
|
1121
1122
|
invalid: [
|
|
1122
1123
|
nil,
|
|
@@ -2167,7 +2168,8 @@ TEST_DATA = {
|
|
|
2167
2168
|
'',
|
|
2168
2169
|
'invalid_zip',
|
|
2169
2170
|
'1234',
|
|
2170
|
-
'123456789'
|
|
2171
|
+
'123456789',
|
|
2172
|
+
'12345'
|
|
2171
2173
|
]
|
|
2172
2174
|
},
|
|
2173
2175
|
BJ: {
|
|
@@ -82,6 +82,14 @@ describe ValidatesZipcode, '.valid?' do
|
|
|
82
82
|
expect(ValidatesZipcode.valid?('12345', 'ZZ')).to eq(true)
|
|
83
83
|
end
|
|
84
84
|
|
|
85
|
+
it "is false with a malformed country code that is not a valid ISO 3166-1 alpha-2 code" do
|
|
86
|
+
expect(ValidatesZipcode.valid?('Sw1A 2aA', 'UKXXXXX')).to eq(false)
|
|
87
|
+
expect(ValidatesZipcode.valid?('12345', 'USA')).to eq(false) # 3 letters
|
|
88
|
+
expect(ValidatesZipcode.valid?('12345', 'U')).to eq(false) # 1 letter
|
|
89
|
+
expect(ValidatesZipcode.valid?('12345', '12')).to eq(false) # digits
|
|
90
|
+
expect(ValidatesZipcode.valid?('12345', '')).to eq(false) # empty
|
|
91
|
+
end
|
|
92
|
+
|
|
85
93
|
it "is true with an excluded country code - we don't want those to fail and nil is hairy" do
|
|
86
94
|
expect(ValidatesZipcode.valid?('XXXX!!!XXXX', 'PA', excluded_country_codes: %w[PA])).to eq(true)
|
|
87
95
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: validates_zipcode
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- David Gil
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: activemodel
|
|
@@ -155,7 +154,6 @@ homepage: http://github.com/dgilperez/validates_zipcode
|
|
|
155
154
|
licenses:
|
|
156
155
|
- MIT
|
|
157
156
|
metadata: {}
|
|
158
|
-
post_install_message:
|
|
159
157
|
rdoc_options: []
|
|
160
158
|
require_paths:
|
|
161
159
|
- lib
|
|
@@ -170,8 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
170
168
|
- !ruby/object:Gem::Version
|
|
171
169
|
version: '0'
|
|
172
170
|
requirements: []
|
|
173
|
-
rubygems_version: 3.
|
|
174
|
-
signing_key:
|
|
171
|
+
rubygems_version: 3.6.9
|
|
175
172
|
specification_version: 4
|
|
176
173
|
summary: Localizable zipcode validation for Rails.
|
|
177
174
|
test_files:
|