Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cac52c9

Browse filesBrowse files
committed
Merge pull request PyMySQL#24 from PyMySQL/fix/escape-string
Fix _mysql.escape_string()
2 parents 4481bdb + fae710d commit cac52c9
Copy full SHA for cac52c9

File tree

Expand file treeCollapse file tree

2 files changed

+7
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+7
-1
lines changed

‎_mysql.c

Copy file name to clipboardExpand all lines: _mysql.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ _mysql_escape_string(
10791079
PyObject *str;
10801080
char *in, *out;
10811081
int len, size;
1082-
if (!PyArg_ParseTuple(args, "y#:escape_string", &in, &size)) return NULL;
1082+
if (!PyArg_ParseTuple(args, "s#:escape_string", &in, &size)) return NULL;
10831083
str = PyBytes_FromStringAndSize((char *) NULL, size*2+1);
10841084
if (!str) return PyErr_NoMemory();
10851085
out = PyBytes_AS_STRING(str);

‎tests/test_MySQLdb_nonstandard.py

Copy file name to clipboardExpand all lines: tests/test_MySQLdb_nonstandard.py
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ def test_client_info(self):
4141
def test_thread_safe(self):
4242
self.assertTrue(isinstance(_mysql.thread_safe(), int))
4343

44+
def test_escape_string(self):
45+
self.assertEqual(_mysql.escape_string(b'foo"bar'),
46+
b'foo\\"bar', "escape byte string")
47+
self.assertEqual(_mysql.escape_string(u'foo"bar'),
48+
b'foo\\"bar', "escape unicode string")
49+
4450

4551
class CoreAPI(unittest.TestCase):
4652
"""Test _mysql interaction internals."""

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.