From 0bf2866211d095a18a5c61d7af644c8e17486e6e Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Wed, 16 Dec 2009 22:05:13 +0000 Subject: Bug Fixes --------- - When a route with the same name as a previously registered route was added, the old route was not removed from the mapper's routelist. Symptom: the old registered route would be used (and possibly matched) during route lookup when it should not have had a chance to ever be used. --- CHANGES.txt | 12 ++++++++++++ repoze/bfg/tests/test_urldispatch.py | 11 +++++++++++ repoze/bfg/urldispatch.py | 3 +++ 3 files changed, 26 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index a74a901da..d84e8cb7f 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,15 @@ +Next release +============ + +Bug Fixes +--------- + +- When a route with the same name as a previously registered route was + added, the old route was not removed from the mapper's routelist. + Symptom: the old registered route would be used (and possibly + matched) during route lookup when it should not have had a chance to + ever be used. + 1.2a5 (2009-12-10) ================== diff --git a/repoze/bfg/tests/test_urldispatch.py b/repoze/bfg/tests/test_urldispatch.py index 84484b692..861a4fd05 100644 --- a/repoze/bfg/tests/test_urldispatch.py +++ b/repoze/bfg/tests/test_urldispatch.py @@ -67,6 +67,17 @@ class RoutesMapperTests(unittest.TestCase): self.assertEqual(result['match'], None) self.assertEqual(result['route'], None) + def test_connect_name_exists_removes_old(self): + mapper = self._makeOne() + mapper.connect('archives/:action/:article', 'foo') + mapper.connect('archives/:action/:article2', 'foo') + self.assertEqual(len(mapper.routelist), 1) + self.assertEqual(len(mapper.routes), 1) + self.assertEqual(mapper.routes['foo'].path, + 'archives/:action/:article2') + self.assertEqual(mapper.routelist[0].path, + 'archives/:action/:article2') + def test_route_matches(self): mapper = self._makeOne() mapper.connect('archives/:action/:article', 'foo') diff --git a/repoze/bfg/urldispatch.py b/repoze/bfg/urldispatch.py index c577dfa9e..becde3ea2 100644 --- a/repoze/bfg/urldispatch.py +++ b/repoze/bfg/urldispatch.py @@ -28,6 +28,9 @@ class RoutesMapper(object): return self.routelist def connect(self, path, name, factory=None, predicates=()): + if name in self.routes: + oldroute = self.routes[name] + self.routelist.remove(oldroute) route = Route(path, name, factory, predicates) self.routelist.append(route) self.routes[name] = route -- cgit v1.2.3