Skip to content

Commit

Permalink
Merge pull request #13 from sealink/no_match_within_alphanumeric
Browse files Browse the repository at this point in the history
Does not match credit cards numbers that are part of longer pattern
  • Loading branch information
alvinypyim committed Dec 22, 2016
2 parents 195ee1a + 3633b35 commit 1147d94
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
This changelog adheres to [Keep a CHANGELOG](http://keepachangelog.com/).

## [Unreleased]
### Changed
- Does not match credit cards numbers that are part of alphanumerical strings

## [0.2.3] - 2016-12-22
### Fixed
- Ensures that the url returned by the occurrence is filtered
Expand Down
2 changes: 1 addition & 1 deletion lib/sensitive_data_filter/types/credit_card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module CreditCard
SEPRS = SEPARATORS.source + '*'
LENGTHS = (11..19)
CARD = Regexp.new(
LENGTHS.map { |length| /(?=((?<!\d)(?:\d#{SEPRS}){#{length - 1}}\d(?!\d))?)/.source }.join
LENGTHS.map { |length| /(?=(\b(?:\d#{SEPRS}){#{length - 1}}\d\b)?)/.source }.join
)
FILTERED = '[FILTERED]'

Expand Down
30 changes: 30 additions & 0 deletions spec/sensitive_data_filter/types/credit_card_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,41 @@ def validations(cards)
specify { expect(scan).to be_empty }
end

context 'a value that contains valid credit card numbers preceded by numbers' do
let(:value) { '1234111111111111111' }
specify { expect(scan).to be_empty }
end

context 'a value that contains valid credit card numbers followed by numbers' do
let(:value) { '4111111111111111321' }
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 valid credit card numbers between letters' do
let(:value) { 'abc4111111111111111dfg' }
specify { expect(scan).to be_empty }
end

context 'a value that contains valid credit card numbers preceded by letters' do
let(:value) { 'abc4111111111111111' }
specify { expect(scan).to be_empty }
end

context 'a value that contains valid credit card numbers followed by letters' do
let(:value) { '4111111111111111abc' }
specify { expect(scan).to be_empty }
end

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

context 'a value that contains repeated valid credit card numbers' do
let(:value) { 'cc1 4111 1111 1111 1111 cc2 4111 1111 1111 1111 123' }
specify { expect(scan).to eq ['4111 1111 1111 1111', '4111 1111 1111 1111'] }
Expand Down

0 comments on commit 1147d94

Please sign in to comment.