mirror of
https://github.com/python/cpython.git
synced 2025-07-23 19:25:40 +00:00
[Bug #1172763] dumbdbm uses eval() on lines, so it chokes if there's an extra \r on the end of a line; fixed by stripping off trailing whitespace.
This commit is contained in:
parent
eb2608415e
commit
ecdad8575e
2 changed files with 19 additions and 0 deletions
|
@ -81,6 +81,7 @@ class _Database(UserDict.DictMixin):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
for line in f:
|
for line in f:
|
||||||
|
line = line.rstrip()
|
||||||
key, pos_and_siz_pair = eval(line)
|
key, pos_and_siz_pair = eval(line)
|
||||||
self._index[key] = pos_and_siz_pair
|
self._index[key] = pos_and_siz_pair
|
||||||
f.close()
|
f.close()
|
||||||
|
|
|
@ -74,6 +74,24 @@ class DumbDBMTestCase(unittest.TestCase):
|
||||||
self.assertEqual(f['1'], 'hello2')
|
self.assertEqual(f['1'], 'hello2')
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
def test_line_endings(self):
|
||||||
|
# test for bug #1172763: dumbdbm would die if the line endings
|
||||||
|
# weren't what was expected.
|
||||||
|
f = dumbdbm.open(_fname)
|
||||||
|
f['1'] = 'hello'
|
||||||
|
f['2'] = 'hello2'
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
# Mangle the file by adding \r before each newline
|
||||||
|
data = open(_fname + '.dir').read()
|
||||||
|
data = data.replace('\n', '\r\n')
|
||||||
|
open(_fname + '.dir', 'wb').write(data)
|
||||||
|
|
||||||
|
f = dumbdbm.open(_fname)
|
||||||
|
self.assertEqual(f['1'], 'hello')
|
||||||
|
self.assertEqual(f['2'], 'hello2')
|
||||||
|
|
||||||
|
|
||||||
def read_helper(self, f):
|
def read_helper(self, f):
|
||||||
keys = self.keys_helper(f)
|
keys = self.keys_helper(f)
|
||||||
for key in self._dict:
|
for key in self._dict:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue