Skip to content

Commit

Permalink
Improve and sync number regex in URL/point form.
Browse files Browse the repository at this point in the history
This should prevent errors where a submission such as '53.8487,2.9295.'
was matched and then could not be reversed.
  • Loading branch information
dracos committed Feb 27, 2017
1 parent dcbca66 commit 7a27c43
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mapit/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

format_end = '(?:\.(?P<format>html|json))?'

number = '-?\d*\.?\d+'
number = '[+-]?(?:\d*\.)?\d+'

urlpatterns = [
url(r'^$', render, {'template_name': 'mapit/index.html'}, 'mapit_index'),
Expand Down
3 changes: 2 additions & 1 deletion mapit/views/areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from mapit.shortcuts import output_json, output_html, output_polygon, get_object_or_404, set_timeout
from mapit.middleware import ViewException
from mapit.ratelimitcache import ratelimit
form mapit.urls import number as re_number
from mapit import countries
from mapit.iterables import iterdict
from mapit.geometryserialiser import GeometrySerialiser, TransformError
Expand Down Expand Up @@ -413,7 +414,7 @@ def point_form_submitted(request):
latlon = request.POST.get('pc', None)
if not request.method == 'POST' or not latlon:
return redirect('mapit_index')
m = re.match('\s*([0-9.-]+)\s*,\s*([0-9.-]+)', latlon)
m = re.match('\s*(%s)\s*,\s*(%s)' % (re_number, re_number), latlon)
if not m:
return redirect('mapit_index')
lat, lon = m.groups()
Expand Down

0 comments on commit 7a27c43

Please sign in to comment.