Skip to content

Commit

Permalink
Merge branch 'master' into filter_uri
Browse files Browse the repository at this point in the history
  • Loading branch information
alxberardi committed Dec 21, 2016
2 parents 48d20d5 + f6bb2cc commit dcd7c51
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,10 @@ This changelog adheres to [Keep a CHANGELOG](http://keepachangelog.com/).
### Fixed
- Ensures that the url returned by the occurrence is filtered

### Changed
- Does not match credit cards numbers that are part of longer numbers


## [0.2.2] - 2016-12-21
### Fixed
- Implements stricter credit cards pattern matching
Expand Down
6 changes: 4 additions & 2 deletions lib/sensitive_data_filter/types/credit_card.rb
Expand Up @@ -7,8 +7,10 @@ module CreditCard
SEPARATORS = /[\s-]/
SEPRS = SEPARATORS.source + '*'
LENGTHS = (11..19)
CARD = Regexp.new(LENGTHS.map { |l| /(?=((?:\d#{SEPRS}){#{l - 1}}\d)?)/.source }.join)
FILTERED = '[FILTERED]'
CARD = Regexp.new(
LENGTHS.map { |length| /(?=((?<!\d)(?:\d#{SEPRS}){#{length - 1}}\d(?!\d))?)/.source }.join
)
FILTERED = '[FILTERED]'

module_function def valid?(number)
return false unless number.is_a? String
Expand Down
9 changes: 7 additions & 2 deletions spec/sensitive_data_filter/types/credit_card_spec.rb
Expand Up @@ -62,8 +62,13 @@ def validations(cards)
end

context 'a value that contains valid credit card numbers in a longer numerical pattern' do
let(:value) { '1234111 1111 1111 1111234' }
specify { expect(scan).to eq ['34111 1111 1111 11', '4111 1111 1111 1111'] }
let(:value) { '1234111111111111111234' }
specify { expect(scan).to be_empty }
end

context 'a value that contains a valid credit card number separated from other numbers' do
let(:value) { '123 4111 1111 1111 1111 234' }
specify { expect(scan).to eq ['4111 1111 1111 1111'] }
end

context 'a value that contains repeated valid credit card numbers' do
Expand Down

0 comments on commit dcd7c51

Please sign in to comment.