summaryrefslogtreecommitdiffstats
path: root/Lib/bsddb/test
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2007-11-01 21:08:14 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2007-11-01 21:08:14 (GMT)
commitaae141a7513bb6ff44834f9a2459632d7a5f6b00 (patch)
tree72d98580a040674876bdb2919f2ac950e967e9b0 /Lib/bsddb/test
parent744b32a544bae1bd4e40730802103ae823f3c673 (diff)
downloadcpython-aae141a7513bb6ff44834f9a2459632d7a5f6b00.zip
cpython-aae141a7513bb6ff44834f9a2459632d7a5f6b00.tar.gz
cpython-aae141a7513bb6ff44834f9a2459632d7a5f6b00.tar.bz2
Fix bug introduced in revision 58385. Database keys could no longer
have NULL bytes in them. Replace the errant strdup with a malloc+memcpy. Adds a unit test for the correct behavior.
Diffstat (limited to 'Lib/bsddb/test')
-rw-r--r--Lib/bsddb/test/test_misc.py25
1 files changed, 21 insertions, 4 deletions
diff --git a/Lib/bsddb/test/test_misc.py b/Lib/bsddb/test/test_misc.py
index 3e63354..1212581 100644
--- a/Lib/bsddb/test/test_misc.py
+++ b/Lib/bsddb/test/test_misc.py
@@ -30,10 +30,8 @@ class MiscTestCase(unittest.TestCase):
os.remove(self.filename)
except OSError:
pass
- import glob
- files = glob.glob(os.path.join(self.homeDir, '*'))
- for file in files:
- os.remove(file)
+ import shutil
+ shutil.rmtree(self.homeDir)
def test01_badpointer(self):
dbs = dbshelve.open(self.filename)
@@ -73,6 +71,25 @@ class MiscTestCase(unittest.TestCase):
db1.close()
os.unlink(self.filename)
+ def test05_key_with_null_bytes(self):
+ try:
+ db1 = db.DB()
+ db1.open(self.filename, None, db.DB_HASH, db.DB_CREATE)
+ db1['a'] = 'eh?'
+ db1['a\x00'] = 'eh zed.'
+ db1['a\x00a'] = 'eh zed eh?'
+ db1['aaa'] = 'eh eh eh!'
+ keys = db1.keys()
+ keys.sort()
+ self.assertEqual(['a', 'a\x00', 'a\x00a', 'aaa'], keys)
+ self.assertEqual(db1['a'], 'eh?')
+ self.assertEqual(db1['a\x00'], 'eh zed.')
+ self.assertEqual(db1['a\x00a'], 'eh zed eh?')
+ self.assertEqual(db1['aaa'], 'eh eh eh!')
+ finally:
+ db1.close()
+ os.unlink(self.filename)
+
#----------------------------------------------------------------------