Skip to content

Instantly share code, notes, and snippets.

@Burick
Forked from zirosas/mysql_real_escape_string.js
Last active January 3, 2018 23:41
Show Gist options
  • Save Burick/74301fde95564365d0de621b9eb9b4c0 to your computer and use it in GitHub Desktop.
Save Burick/74301fde95564365d0de621b9eb9b4c0 to your computer and use it in GitHub Desktop.
замена функции mysql_real_escape_string
function mysql_real_escape_string (str) {
if(!str) return '';
return str.replace(/[\0\x08\x09\x1a\n\r"'\\\%]/g, function (char) {
switch (char) {
case "\0":
return "\\0";
case "\x08":
return "\\b";
case "\x09":
return "\\t";
case "\x1a":
return "\\z";
case "\n":
return "\\n";
case "\r":
return "\\r";
case "\"":
case "'":
case "\\":
case "%":
return "\\"+char; // prepends a backslash to backslash, percent,
// and double/single quotes
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment