I have a regex to add thousand separators and I get a Denial of Service security hotspot in sonarcloud.
I have this code
function thousandSeparator(value: number | string | null | undefined) { return value?.toString().replace(/B(?=(d{3})+(?!d))/g, "u00a0"); }
and this is the explaination of the security hotspot
Make sure the regex used here, which is vulnerable to super-linear runtime due to backtracking, cannot lead to denial of service.
How can I fix this?
user26094131 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.