Skip to content

Commit 9615672

Browse files
committed
Allow parsing boolean both upper and lowercase
Reportedly useful on H2 databases. Close psycopg#965
1 parent 5e9572a commit 9615672

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

psycopg/typecast_basic.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,27 @@ typecast_UNICODE_cast(const char *s, Py_ssize_t len, PyObject *curs)
114114
static PyObject *
115115
typecast_BOOLEAN_cast(const char *s, Py_ssize_t len, PyObject *curs)
116116
{
117-
PyObject *res;
117+
PyObject *res = NULL;
118118

119119
if (s == NULL) { Py_RETURN_NONE; }
120120

121-
if (s[0] == 't')
122-
res = Py_True;
123-
else
124-
res = Py_False;
121+
switch (s[0]) {
122+
case 't':
123+
case 'T':
124+
res = Py_True;
125+
break;
126+
127+
case 'f':
128+
case 'F':
129+
res = Py_False;
130+
break;
131+
132+
default:
133+
PyErr_Format(InterfaceError, "can't parse boolean: '%s'", s);
134+
break;
135+
}
125136

126-
Py_INCREF(res);
137+
Py_XINCREF(res);
127138
return res;
128139
}
129140

0 commit comments

Comments
 (0)