Skip to content

Commit

Permalink
Fixed Python-Markdown#85. Odict now handles link errors correctly.
Browse files Browse the repository at this point in the history
Also added a test. Thanks for the report.
  • Loading branch information
Waylan Limberg committed Mar 19, 2012
1 parent f842c9a commit 4dd11ab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions markdown/odict.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ def link(self, key, location):
""" Change location of an existing item. """
n = self.keyOrder.index(key)
del self.keyOrder[n]
i = self.index_for_location(location)
try:
i = self.index_for_location(location)
if i is not None:
self.keyOrder.insert(i, key)
else:
self.keyOrder.append(key)
except Error:
except Exception as e:
# restore to prevent data loss and reraise
self.keyOrder.insert(n, key)
raise Error
raise e
8 changes: 8 additions & 0 deletions tests/test_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ def testChangeOrder(self):
[('first', 'This'), ('fourth', 'self'),
('third', 'a'), ('fifth', 'test')])

def textBadLink(self):
""" Test OrderedDict change order with bad location. """
self.assertRaises(ValueError, self.odict.link('fourth', '<bad'))
# Check for data integrity ("fourth" wasn't deleted).'
self.assertEqual(self.odict.items(),
[('first', 'This'), ('third', 'a'),
('fourth', 'self'), ('fifth', 'test')])

class TestErrors(unittest.TestCase):
""" Test Error Reporting. """

Expand Down

0 comments on commit 4dd11ab

Please sign in to comment.