Commits

Brian Kearns  committed 6cbb87a

test and fix for _marshal.dump_unicode (fixes issue 1420)

  • Participants
  • Parent commits c6ce849

Comments (0)

Files changed (2)

File lib_pypy/_marshal.py

     def dump_unicode(self, x):
         self._write(TYPE_UNICODE)
         #s = x.encode('utf8')
-        s, len_s = utf_8_encode(x)
-        self.w_long(len_s)
+        s = utf_8_encode(x)[0]
+        self.w_long(len(s))
         self._write(s)
     try:
         unicode
         n = self.r_long()
         s = self._read(n)
         #ret = s.decode('utf8')
-        ret, len_ret = utf_8_decode(s)
+        ret = utf_8_decode(s)[0]
         return ret
     dispatch[TYPE_UNICODE] = load_unicode
 

File pypy/module/test_lib_pypy/test_marshal_extra.py

 def test_load_truncated_string():
     s = '(\x02\x00\x00\x00i\x03\x00\x00\x00sB\xf9\x00\x00\nabcd'
     py.test.raises(EOFError, marshal.loads, s)
+
+def test_dump_unicode_length():
+    s = u'123\xe9'
+    r = marshal.dumps(s)
+    assert r == b'u\x05\x00\x00\x00123\xc3\xa9'