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): ...@@ -59,25 +59,25 @@ class TestPrettyPrinters(test_libcython_in_gdb.DebugTestCase):
assert b'"' not in string assert b'"' not in string
# ensure double quotes # 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) return self.pyobject_fromcode(code, gdbvar=gdbvar)
def alloc_unicodestring(self, string, gdbvar=None): def alloc_unicodestring(self, string, gdbvar=None):
self.alloc_bytestring(string.encode('UTF-8'), gdbvar='_temp')
postfix = libpython.get_inferior_unicode_postfix() 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( 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) gdbvar=gdbvar)
def test_bytestring(self): def test_bytestring(self):
bytestring = self.alloc_bytestring("spam") bytestring = self.alloc_bytestring(b"spam")
if inferior_python_version < (3, 0): if inferior_python_version < (3, 0):
bytestring_class = libpython.PyStringObjectPtr bytestring_class = libpython.PyStringObjectPtr
expected = repr("spam") expected = repr(b"spam")
else: else:
bytestring_class = libpython.PyBytesObjectPtr bytestring_class = libpython.PyBytesObjectPtr
expected = "b'spam'" expected = "b'spam'"
...@@ -88,7 +88,7 @@ class TestPrettyPrinters(test_libcython_in_gdb.DebugTestCase): ...@@ -88,7 +88,7 @@ class TestPrettyPrinters(test_libcython_in_gdb.DebugTestCase):
def test_unicode(self): def test_unicode(self):
unicode_string = self.alloc_unicodestring(u"spam ἄλφα") unicode_string = self.alloc_unicodestring(u"spam ἄλφα")
expected = "'spam ἄλφα'" expected = u"'spam ἄλφα'"
if inferior_python_version < (3, 0): if inferior_python_version < (3, 0):
expected = 'u' + expected 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