From e631ebbc37d1aeb21184d1ff2dbf7eab588decfa Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Sun, 26 Feb 2017 16:09:36 +0100 Subject: [PATCH] Trap invalid URLs for submission forms I still haven't figured out where these come from, but generate a proper 404 when the URL is malformatted rather than trying to render it and crash with an exception --- pgweb/util/helpers.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pgweb/util/helpers.py b/pgweb/util/helpers.py index 71134bd2..a203b0ef 100644 --- a/pgweb/util/helpers.py +++ b/pgweb/util/helpers.py @@ -1,6 +1,6 @@ from django.shortcuts import render_to_response, get_object_or_404 from pgweb.util.contexts import NavContext -from django.http import HttpResponseRedirect +from django.http import HttpResponseRedirect, Http404 from django.template import Context from django.template.loader import get_template import django.utils.xmlutils @@ -10,6 +10,10 @@ def simple_form(instancetype, itemid, request, formclass, formtemplate='base/for instance = instancetype() else: # Regular form item, attempt to edit it + try: + i = int(itemid) + except ValueError: + raise Http404("Invalid URL") if createifempty: (instance, wascreated) = instancetype.objects.get_or_create(pk=itemid) else: -- 2.39.5