Created
November 9, 2019 20:27
-
-
Save gingeleski/3a88a5286bcf98ba33b28b95f430e4ff to your computer and use it in GitHub Desktop.
Sanitize CSV data from having any executable functions in its cells.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var csvData = 'generate,=your(stuff),@here'; | |
// Protect against CSV injection - ensure cells don't have ( ), or start with = @ + - unless followed by digit | |
csvData = csvData.replace(/([()])/g, '').replace(/(^|[,\n\r])([=@+-]+)(?=[\D\.])/g, (match, offset, string) => { | |
return match.replace(/[^,\n\r]/g, ''); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment