credit_card_sanitizer 0.6.4 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/credit_card_sanitizer.rb +8 -9
- metadata +3 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0987ab87c5cdbae11ccb6de48bde377f7330e023
|
4
|
+
data.tar.gz: cbf5ba1b56bb368884b044e9e53c864456f5bb6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf6fcc71dbb34c05de6df3f55daa83568e20b5c31c118f889b4f805809da2de8c780035e796923d6115f34bf100b560c7c9652a5c9c512903cdb72bbf1b7bd5c
|
7
|
+
data.tar.gz: 650a14b4b476fbba4e03c3476ff6e9639543a13378cbb3ffae67ab1c73bb448e1be72463e131994822b2b8be86a3081a24961a197ccd344718035cebe4791e28
|
@@ -5,12 +5,11 @@ require 'securerandom'
|
|
5
5
|
require 'tracking_number'
|
6
6
|
|
7
7
|
class CreditCardSanitizer
|
8
|
-
|
9
8
|
# https://github.com/Shopify/active_merchant/blob/master/lib/active_merchant/billing/credit_card_methods.rb#L5-L18
|
10
9
|
CARD_COMPANIES = {
|
11
10
|
'visa' => /^4\d{12}(\d{3})?(\d{3})?$/,
|
12
11
|
'master' => /^(5[1-5]\d{4}|677189)\d{10}$/,
|
13
|
-
'discover' => /^(6011|65\d{2}|64[4-9]\d)\d{12}|(62\d{14})$/,
|
12
|
+
'discover' => /^((6011|65\d{2}|64[4-9]\d)\d{12}|(62\d{14}))$/,
|
14
13
|
'american_express' => /^3[47]\d{13}$/,
|
15
14
|
'diners_club' => /^3(0[0-5]|[68]\d)\d{11}$/,
|
16
15
|
'jcb' => /^35(28|29|[3-8]\d)\d{12}$/,
|
@@ -20,7 +19,7 @@ class CreditCardSanitizer
|
|
20
19
|
'maestro' => /^(5[06-8]|6\d)\d{10,17}$/,
|
21
20
|
'forbrugsforeningen' => /^600722\d{10}$/,
|
22
21
|
'laser' => /^(6304|6706|6709|6771(?!89))\d{8}(\d{4}|\d{6,7})?$/
|
23
|
-
}
|
22
|
+
}.freeze
|
24
23
|
|
25
24
|
CARD_NUMBER_GROUPINGS = {
|
26
25
|
'visa' => [[4, 4, 4, 4]],
|
@@ -35,7 +34,7 @@ class CreditCardSanitizer
|
|
35
34
|
'maestro' => [[4], [5]],
|
36
35
|
'forbrugsforeningen' => [[4, 4, 4, 4]],
|
37
36
|
'laser' => [[4, 4, 4, 4]]
|
38
|
-
}
|
37
|
+
}.freeze
|
39
38
|
|
40
39
|
ACCEPTED_PREFIX = /(?:cc|card|visa|amex)\z/i
|
41
40
|
ACCEPTED_POSTFIX = /\Aex/i
|
@@ -55,7 +54,7 @@ class CreditCardSanitizer
|
|
55
54
|
use_groupings: false,
|
56
55
|
exclude_tracking_numbers: false,
|
57
56
|
parse_flanking: false
|
58
|
-
}
|
57
|
+
}.freeze
|
59
58
|
|
60
59
|
attr_reader :settings
|
61
60
|
|
@@ -134,7 +133,7 @@ class CreditCardSanitizer
|
|
134
133
|
#
|
135
134
|
# Returns a Proc that takes the key/value of the request parameter.
|
136
135
|
def self.parameter_filter(options = {})
|
137
|
-
|
136
|
+
proc { |_, value| new(options).sanitize!(value) if value.is_a?(String) }
|
138
137
|
end
|
139
138
|
|
140
139
|
private
|
@@ -166,12 +165,12 @@ class CreditCardSanitizer
|
|
166
165
|
end
|
167
166
|
end
|
168
167
|
|
169
|
-
def
|
168
|
+
def tracking?(candidate, options)
|
170
169
|
options[:exclude_tracking_numbers] && TrackingNumber.new(candidate.numbers).valid?
|
171
170
|
end
|
172
171
|
|
173
172
|
def valid_numbers?(candidate, options)
|
174
|
-
LuhnChecksum.valid?(candidate.numbers) && valid_company_prefix?(candidate.numbers) && valid_grouping?(candidate, options) && !
|
173
|
+
LuhnChecksum.valid?(candidate.numbers) && valid_company_prefix?(candidate.numbers) && valid_grouping?(candidate, options) && !tracking?(candidate, options)
|
175
174
|
end
|
176
175
|
|
177
176
|
def valid_context?(candidate, options)
|
@@ -204,7 +203,7 @@ class CreditCardSanitizer
|
|
204
203
|
|
205
204
|
def without_expiration(text)
|
206
205
|
expiration_date_boundary = SecureRandom.hex.tr('0123456789', 'ABCDEFGHIJ')
|
207
|
-
text.gsub!(EXPIRATION_DATE) { |expiration_date| "#{expiration_date_boundary}#{expiration_date}#{expiration_date_boundary}"
|
206
|
+
text.gsub!(EXPIRATION_DATE) { |expiration_date| "#{expiration_date_boundary}#{expiration_date}#{expiration_date_boundary}" }
|
208
207
|
yield
|
209
208
|
text.gsub!(expiration_date_boundary, '')
|
210
209
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: credit_card_sanitizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Chapweske
|
@@ -10,64 +10,8 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-
|
13
|
+
date: 2017-08-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
name: rake
|
17
|
-
requirement: !ruby/object:Gem::Requirement
|
18
|
-
requirements:
|
19
|
-
- - ">="
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :development
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
requirements:
|
26
|
-
- - ">="
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
version: '0'
|
29
|
-
- !ruby/object:Gem::Dependency
|
30
|
-
name: bundler
|
31
|
-
requirement: !ruby/object:Gem::Requirement
|
32
|
-
requirements:
|
33
|
-
- - ">="
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version: '0'
|
36
|
-
type: :development
|
37
|
-
prerelease: false
|
38
|
-
version_requirements: !ruby/object:Gem::Requirement
|
39
|
-
requirements:
|
40
|
-
- - ">="
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: '0'
|
43
|
-
- !ruby/object:Gem::Dependency
|
44
|
-
name: luhnacy
|
45
|
-
requirement: !ruby/object:Gem::Requirement
|
46
|
-
requirements:
|
47
|
-
- - ">="
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: '0'
|
50
|
-
type: :development
|
51
|
-
prerelease: false
|
52
|
-
version_requirements: !ruby/object:Gem::Requirement
|
53
|
-
requirements:
|
54
|
-
- - ">="
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: '0'
|
57
|
-
- !ruby/object:Gem::Dependency
|
58
|
-
name: byebug
|
59
|
-
requirement: !ruby/object:Gem::Requirement
|
60
|
-
requirements:
|
61
|
-
- - ">="
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
version: '0'
|
64
|
-
type: :development
|
65
|
-
prerelease: false
|
66
|
-
version_requirements: !ruby/object:Gem::Requirement
|
67
|
-
requirements:
|
68
|
-
- - ">="
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
version: '0'
|
71
15
|
- !ruby/object:Gem::Dependency
|
72
16
|
name: luhn_checksum
|
73
17
|
requirement: !ruby/object:Gem::Requirement
|
@@ -124,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
68
|
version: '0'
|
125
69
|
requirements: []
|
126
70
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.
|
71
|
+
rubygems_version: 2.4.5.1
|
128
72
|
signing_key:
|
129
73
|
specification_version: 4
|
130
74
|
summary: Credit card sanitizer
|