CSV Export - encode quotes #808

This commit is contained in:
jokob-sk
2024-09-29 08:18:00 +10:00
parent e3b2039257
commit 02077d4654
4 changed files with 51 additions and 14 deletions

View File

@@ -383,6 +383,26 @@ function isValidJSON(jsonString) {
}
}
// method to sanitize input so that HTML and other things don't break
function encodeSpecialChars(str) {
return str
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;');
}
function decodeSpecialChars(str) {
return str
.replace(/&amp;/g, '&')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&quot;/g, '"')
.replace(/&#039;/g, '\'');
}
// -----------------------------------------------------------------------------
// General utilities
// -----------------------------------------------------------------------------