Skip to content

Commit

Permalink
PP-12237 Fix permissive regex
Browse files Browse the repository at this point in the history
Code QL flagged that the `A-z` in the regex was a "Suspicious
character range that is equivalent to [A-Z\[\\]^_`a-z]."
  • Loading branch information
stephencdaly committed Mar 6, 2024
1 parent 84f4372 commit 84f1c39
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/utils/validation/server-side-form-validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function validatePostcode (postcode, countryCode) {
return validReturnObject
}

if (!/^[A-z0-9 ]+$/.test(postcode)) {
if (!/^[A-Za-z0-9 ]+$/.test(postcode)) {
return notValidReturnObject('Enter a real postcode')
}

Expand Down
7 changes: 7 additions & 0 deletions app/utils/validation/server-side-form-validations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ describe('Server side form validations', () => {
})
})

it('should not be valid when postcode is UK postcode with ^ character', () => {
expect(validations.validatePostcode('NW1^ 5GH')).to.deep.equal({
valid: false,
message: 'Enter a real postcode'
})
})

it('should not be valid when postcode is not UK postcode and country not provided', () => {
expect(validations.validatePostcode('CA90210')).to.deep.equal({
valid: false,
Expand Down

0 comments on commit 84f1c39

Please sign in to comment.