Commit a7b253ab authored by Stefan Behnel's avatar Stefan Behnel

Make string handling and escaping in gdb tests safe.

parent 506f1fdf
......@@ -59,25 +59,25 @@ class TestPrettyPrinters(test_libcython_in_gdb.DebugTestCase):
assert b'"' not in string
# ensure double quotes
code = '(PyObject *) %s("%s", %d)' % (funcname, string, len(string))
code = '(PyObject *) %s("%s", %d)' % (funcname, string.decode('iso8859-1'), len(string))
return self.pyobject_fromcode(code, gdbvar=gdbvar)
def alloc_unicodestring(self, string, gdbvar=None):
self.alloc_bytestring(string.encode('UTF-8'), gdbvar='_temp')
postfix = libpython.get_inferior_unicode_postfix()
funcname = 'PyUnicode%s_FromEncodedObject' % (postfix,)
funcname = 'PyUnicode%s_DecodeUnicodeEscape' % (postfix,)
data = string.encode("unicode_escape").decode('iso8859-1')
return self.pyobject_fromcode(
'(PyObject *) %s($_temp, "UTF-8", "strict")' % funcname,
'(PyObject *) %s("%s", %d, "strict")' % (
funcname, data.replace('"', r'\"').replace('\\', r'\\'), len(data)),
gdbvar=gdbvar)
def test_bytestring(self):
bytestring = self.alloc_bytestring("spam")
bytestring = self.alloc_bytestring(b"spam")
if inferior_python_version < (3, 0):
bytestring_class = libpython.PyStringObjectPtr
expected = repr("spam")
expected = repr(b"spam")
else:
bytestring_class = libpython.PyBytesObjectPtr
expected = "b'spam'"
......@@ -88,7 +88,7 @@ class TestPrettyPrinters(test_libcython_in_gdb.DebugTestCase):
def test_unicode(self):
unicode_string = self.alloc_unicodestring(u"spam ἄλφα")
expected = "'spam ἄλφα'"
expected = u"'spam ἄλφα'"
if inferior_python_version < (3, 0):
expected = 'u' + expected
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment