Skip to content

Commit

Permalink
Merge pull request #2043 from alphagov/postcode-redaction
Browse files Browse the repository at this point in the history
Update postcode regex for PII stripping
  • Loading branch information
sihugh authored May 4, 2021
2 parents 859e029 + 727cf95 commit 354893f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
## Unpublished
* Remove unused i18n keys ([PR #2038](https://github.com/alphagov/govuk_publishing_components/pull/2038))

## Unreleased

* Update postcode regex for PII stripping ([PR #2043](https://github.com/alphagov/govuk_publishing_components/pull/2043))

## 24.10.0

* Resolve IE11 accordion gem doc duplication ([PR #2036](https://github.com/alphagov/govuk_publishing_components/pull/2036))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

var GOVUK = global.GOVUK || {}
var EMAIL_PATTERN = /[^\s=/?&]+(?:@|%40)[^\s=/?&]+/g
var POSTCODE_PATTERN = /[A-PR-UWYZ][A-HJ-Z]?[0-9][0-9A-HJKMNPR-Y]?(?:[\s+]|%20)*[0-9](?!refund)[ABD-HJLNPQ-Z]{2,3}/gi
var POSTCODE_PATTERN = /\b[A-PR-UWYZ][A-HJ-Z]?[0-9][0-9A-HJKMNPR-Y]?(?:[\s+]|%20)*[0-9](?!refund)[ABD-HJLNPQ-Z]{2,3}\b/gi
var DATE_PATTERN = /\d{4}(-?)\d{2}(-?)\d{2}/g
var ESCAPE_REGEX_PATTERN = /[|\\{}()[\]^$+*?.]/g

Expand Down
18 changes: 13 additions & 5 deletions spec/javascripts/govuk_publishing_components/analytics/pii.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@ describe('GOVUK.PII', function () {
var obj = {
email: 'this is [email protected] address',
postcode: 'this is a sw1a 1aa postcode',
date: 'this is a 2019-01-21 date'
date: 'this is a 2019-01-21 date',
uuid: 'd6c2de5d-ef90-45d1-82d4-5f2438369eea'
}

var strippedObj = {
email: 'this is [email] address',
postcode: 'this is a [postcode] postcode',
date: 'this is a [date] date'
date: 'this is a [date] date',
uuid: 'd6c2de5d-ef90-45d1-82d4-5f2438369eea'
}

obj = pii.stripPII(obj)
Expand Down Expand Up @@ -122,8 +124,14 @@ describe('GOVUK.PII', function () {

it('observes the meta tag and strips out postcodes', function () {
expect(pii.stripPostcodePII).toEqual(true)
var string = pii.stripPII('this is [email protected] address, this is a sw1a 1aa postcode, this is a long GL194LYX postcode, this is a 2019-01-21 date, this is a p800refund')
expect(string).toEqual('this is [email] address, this is a [postcode] postcode, this is a long [postcode] postcode, this is a 2019-01-21 date, this is a p800refund')
var string = pii.stripPII('this is [email protected] address, this is a sw1a 1aa postcode, this is a long GL194LYX postcode, this is a 2019-01-21 date, this is a d6c2de5d-ef90-45d1-82d4-5f2438369eea content ID, this is a p800refund')
expect(string).toEqual('this is [email] address, this is a [postcode] postcode, this is a long [postcode] postcode, this is a 2019-01-21 date, this is a d6c2de5d-ef90-45d1-82d4-5f2438369eea content ID, this is a p800refund')
})

it('doesn\'t strip out UUIDs in URLs', function () {
expect(pii.stripPostcodePII).toEqual(true)
var string = pii.stripPII('gov.uk/thing?postcode=sw1a1aa&uuid=d6c2de5d-ef90-45d1-82d4-5f2438369eea')
expect(string).toEqual('gov.uk/thing?postcode=[postcode]&uuid=d6c2de5d-ef90-45d1-82d4-5f2438369eea')
})
})

Expand Down Expand Up @@ -167,7 +175,7 @@ describe('GOVUK.PII', function () {
pii = new GOVUK.Pii()
})

it('observes the meta tag and strips out postcodes', function () {
it('observes the meta tag and strips out dates', function () {
expect(pii.stripDatePII).toEqual(true)
var string = pii.stripPII('this is [email protected] address, this is a sw1a 1aa postcode, this is a 2019-01-21 date')
expect(string).toEqual('this is [email] address, this is a sw1a 1aa postcode, this is a [date] date')
Expand Down

0 comments on commit 354893f

Please sign in to comment.