| | 974 | function addslashes (str) { |
| | 975 | // Escapes single quote, double quotes and backslash characters in a string with backslashes |
| | 976 | // |
| | 977 | // version: 908.406 |
| | 978 | // discuss at: http://phpjs.org/functions/addslashes |
| | 979 | // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) |
| | 980 | // + improved by: Ates Goral (http://magnetiq.com) |
| | 981 | // + improved by: marrtins |
| | 982 | // + improved by: Nate |
| | 983 | // + improved by: Onno Marsman |
| | 984 | // + input by: Denny Wardhana |
| | 985 | // + improved by: Brett Zamir (http://brett-zamir.me) |
| | 986 | // * example 1: addslashes("kevin's birthday"); |
| | 987 | // * returns 1: 'kevin\'s birthday' |
| | 988 | |
| | 989 | return (str+'').replace(/([\\"'])/g, "\\$1").replace(/\u0000/g, "\\0"); |
| | 990 | } |
| | 991 | |
| | 992 | function stripslashes (str) { |
| | 993 | // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) |
| | 994 | // + improved by: Ates Goral (http://magnetiq.com) |
| | 995 | // + fixed by: Mick@el |
| | 996 | // + improved by: marrtins |
| | 997 | // + bugfixed by: Onno Marsman |
| | 998 | // + improved by: rezna |
| | 999 | // + input by: Rick Waldron |
| | 1000 | // + reimplemented by: Brett Zamir (http://brett-zamir.me) |
| | 1001 | // * example 1: stripslashes('Kevin\'s code'); |
| | 1002 | // * returns 1: "Kevin's code" |
| | 1003 | // * example 2: stripslashes('Kevin\\\'s code'); |
| | 1004 | // * returns 2: "Kevin\'s code" |
| | 1005 | return (str+'').replace(/\\(.?)/g, function (s, n1) { |
| | 1006 | switch (n1) { |
| | 1007 | case '\\': |
| | 1008 | return '\\'; |
| | 1009 | case '0': |
| | 1010 | return '\0'; |
| | 1011 | case '': |
| | 1012 | return ''; |
| | 1013 | default: |
| | 1014 | return n1; |
| | 1015 | } |
| | 1016 | }); |
| | 1017 | } |
| | 1018 | |