Commits

Maciej Fijalkowski committed d334c17

null chars

Comments (2)

Files changed (2)

lib-python/2.7/test/test_gdbm.py

         self.g = gdbm.open(filename, 'r')
         self.assertEquals(self.g['x'], 'x' * 10000)
 
+    def test_key_with_null_bytes(self):
+        key = 'a\x00b'
+        value = 'c\x00d'
+        self.g = gdbm.open(filename, 'cf')
+        self.g[key] = value
+        self.g.close()
+        self.g = gdbm.open(filename, 'r')
+        self.assertEquals(self.g[key], value)
+        self.assertTrue(key in self.g)
+        self.assertTrue(self.g.has_key(key))
+
 def test_main():
     run_unittest(TestGdbm)
 
         drec = lib.gdbm_fetch(self.ll_dbm, _fromstr(key))
         if not drec.dptr:
             raise KeyError(key)
-        res = ffi.string(drec.dptr, drec.dsize)
+        res = str(ffi.buffer(drec.dptr, drec.dsize))
         lib.free(drec.dptr)
         return res
 
         l = []
         key = lib.gdbm_firstkey(self.ll_dbm)
         while key.dptr:
-            l.append(ffi.string(key.dptr, key.dsize))
+            l.append(str(ffi.buffer(key.dptr, key.dsize)))
             nextkey = lib.gdbm_nextkey(self.ll_dbm, key)
             lib.free(key.dptr)
             key = nextkey
         self._check_closed()
         key = lib.gdbm_firstkey(self.ll_dbm)
         if key.dptr:
-            res = ffi.string(key.dptr, key.dsize)
+            res = str(ffi.buffer(key.dptr, key.dsize))
             lib.free(key.dptr)
             return res
 
         self._check_closed()
         key = lib.gdbm_nextkey(self.ll_dbm, _fromstr(key))
         if key.dptr:
-            res = ffi.string(key.dptr, key.dsize)
+            res = str(ffi.buffer(key.dptr, key.dsize))
             lib.free(key.dptr)
             return res