diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-12-16 22:05:13 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-12-16 22:05:13 +0000 |
| commit | 0bf2866211d095a18a5c61d7af644c8e17486e6e (patch) | |
| tree | 9cc3aeee68706727eca773e8dc8d083c0a68c098 /repoze | |
| parent | 5f5f5c511e5338be9a68f58b01c0f81c70337d25 (diff) | |
| download | pyramid-0bf2866211d095a18a5c61d7af644c8e17486e6e.tar.gz pyramid-0bf2866211d095a18a5c61d7af644c8e17486e6e.tar.bz2 pyramid-0bf2866211d095a18a5c61d7af644c8e17486e6e.zip | |
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.
Diffstat (limited to 'repoze')
| -rw-r--r-- | repoze/bfg/tests/test_urldispatch.py | 11 | ||||
| -rw-r--r-- | repoze/bfg/urldispatch.py | 3 |
2 files changed, 14 insertions, 0 deletions
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 |
