Commit e3a4d88b authored by Raphaël Hertzog's avatar Raphaël Hertzog

Avoid traceback generated with unexpected URL like /e/extend/index.html

The code is only ready to deal with /<hash>/<sourcepackage>.html and the
presence of a supplementary slash caused this exception:

NoReverseMatch at /e/extend/index.html
Reverse for 'dtracker-package-page' with keyword arguments '{'package_name': 'extend/index'}' not found.
1 pattern(s) tried: ['pkg/(?P<package_name>[^/]+)/?$']

Traceback:
File "/usr/lib/python3/dist-packages/django/core/handlers/exception.py" in inner
  41.             response = get_response(request)
File "/usr/lib/python3/dist-packages/django/core/handlers/base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)
File "/usr/lib/python3/dist-packages/django/core/handlers/base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/srv/tracker.debian.org/distro-tracker/distro_tracker/core/views.py" in legacy_package_url_redirect
  96.                     permanent=True)
File "/usr/lib/python3/dist-packages/django/shortcuts.py" in redirect
  56.     return redirect_class(resolve_url(to, *args, **kwargs))
File "/usr/lib/python3/dist-packages/django/shortcuts.py" in resolve_url
  147.         return reverse(to, args=args, kwargs=kwargs)
File "/usr/lib/python3/dist-packages/django/urls/base.py" in reverse
  91.     return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
File "/usr/lib/python3/dist-packages/django/urls/resolvers.py" in _reverse_with_prefix
  497.         raise NoReverseMatch(msg)
parent 3a532693
......@@ -158,6 +158,14 @@ class PackageViewTest(TestCase):
package_url(lib_package),
status_code=301)
def test_legacy_url_redirects_handles_bad_url(self):
"""
Non regression test for a traceback generated with unexpected URL.
"""
url = '/e/extend/index.html'
response = self.client.get(url)
self.assertEqual(response.status_code, 404)
def test_catchall_redirect(self):
"""
Tests that requests made to the root domain are redirected to a package
......
......@@ -81,11 +81,11 @@ admin.autodiscover()
urlpatterns = [
# Redirects for the old PTS package page URLs
url(r'^(?P<package_hash>(lib)?.)/(?P<package_name>(\1).+)\.html$',
url(r'^(?P<package_hash>(lib)?.)/(?P<package_name>(\1)[^/]+)\.html$',
legacy_package_url_redirect),
# Permanent redirect for the old RSS URL
url(r'^(?P<package_hash>(lib)?.)/(?P<package_name>(\1).+)'
url(r'^(?P<package_hash>(lib)?.)/(?P<package_name>(\1)[^/]+)'
r'/news\.rss20\.xml$',
legacy_rss_redirect),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment