Skip to content

Commit

Permalink
Merge pull request #1667 from alphagov/sengi/cwe-20
Browse files Browse the repository at this point in the history
Fix incomplete regex escape function.
  • Loading branch information
sengi authored Mar 26, 2024
2 parents 97b34ea + 846c8ed commit 3aad042
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions app/assets/javascripts/filter-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,9 @@
GOVUKAdmin.redirect(link.attr('href'))
}

// http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/regexp
// Escape ~!@#$%^&*(){}[]`/=?+\|-_;:'",<.>
function escapeStringForRegexp (str) {
return str.replace(/[-[\]/{}()*+?.^$|]/g, '\\$&')
// https://github.com/tc39/proposal-regex-escaping
return str.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&')
}
}
}
Expand Down

0 comments on commit 3aad042

Please sign in to comment.