1
1
mirror of https://github.com/Fabio286/antares.git synced 2025-02-05 11:49:35 +01:00

fix: newline replaced with undefined inside queries

This commit is contained in:
Fabio 2020-08-14 11:06:20 +02:00
parent 7bc10092fe
commit 59e4a79f42

View File

@ -1,6 +1,6 @@
/* eslint-disable no-useless-escape */
// eslint-disable-next-line no-control-regex
const regex = new RegExp(/[\0\x08\x09\x1a\n\r"'\\\%]/g);
const regex = new RegExp(/[\0\x08\x09\x1a\n\r"'\\\%]/gm);
/**
* Escapes a string
@ -9,10 +9,10 @@ const regex = new RegExp(/[\0\x08\x09\x1a\n\r"'\\\%]/g);
* @returns {String}
*/
function sqlEscaper (string) {
return string.replace(regex, (char) => {
return string.replace(regex, char => {
const m = ['\\0', '\\x08', '\\x09', '\\x1a', '\\n', '\\r', '\'', '"', '\\', '\\\\', '%'];
const r = ['\\\\0', '\\\\b', '\\\\t', '\\\\z', '\\\\n', '\\\\r', '\'\'', '""', '\\\\', '\\\\\\\\', '\\%'];
return r[m.indexOf(char)];
return r[m.indexOf(char)] || char;
});
}