compare length of original and escaped string, if they match return the original
This commit is contained in:
parent
1b9e35712f
commit
677c309963
@ -125,18 +125,26 @@ static VALUE rb_mysql_client_query(VALUE self, VALUE sql) {
|
||||
static VALUE rb_mysql_client_escape(VALUE self, VALUE str) {
|
||||
MYSQL * client;
|
||||
VALUE newStr;
|
||||
unsigned long newLen, oldLen;
|
||||
|
||||
Check_Type(str, T_STRING);
|
||||
char escaped[(RSTRING_LEN(str)*2)+1];
|
||||
oldLen = RSTRING_LEN(str);
|
||||
char escaped[(oldLen*2)+1];
|
||||
|
||||
GetMysql2Client(self, client);
|
||||
|
||||
newStr = rb_str_new(escaped, mysql_real_escape_string(client, escaped, RSTRING_PTR(str), RSTRING_LEN(str)));
|
||||
newLen = mysql_real_escape_string(client, escaped, RSTRING_PTR(str), RSTRING_LEN(str));
|
||||
if (newLen == oldLen) {
|
||||
// no need to return a new ruby string if nothing changed
|
||||
return str;
|
||||
} else {
|
||||
newStr = rb_str_new(escaped, newLen);
|
||||
#ifdef HAVE_RUBY_ENCODING_H
|
||||
rb_enc_associate_index(newStr, utf8Encoding);
|
||||
#endif
|
||||
return newStr;
|
||||
}
|
||||
}
|
||||
|
||||
/* Mysql2::Result */
|
||||
static VALUE rb_mysql_result_to_obj(MYSQL_RES * r) {
|
||||
|
Loading…
Reference in New Issue
Block a user