From f97a574196102ef2479da4e519d7cffc7a5fdf6c Mon Sep 17 00:00:00 2001 From: Justin Bronn Date: Fri, 16 Sep 2011 21:19:30 +0000 Subject: [PATCH] Fixed #16864 -- WKT regex now allows negative SRIDs. Thanks, Marcel Dancak for bug report and initial patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16843 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/gis/geometry/regex.py | 2 +- django/contrib/gis/geos/tests/test_geos.py | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/django/contrib/gis/geometry/regex.py b/django/contrib/gis/geometry/regex.py index 1b9e2f46f4..22d16cb4c8 100644 --- a/django/contrib/gis/geometry/regex.py +++ b/django/contrib/gis/geometry/regex.py @@ -4,7 +4,7 @@ import re # to prevent potentially malicious input from reaching the underlying C # library. Not a substitute for good Web security programming practices. hex_regex = re.compile(r'^[0-9A-F]+$', re.I) -wkt_regex = re.compile(r'^(SRID=(?P\d+);)?' +wkt_regex = re.compile(r'^(SRID=(?P\-?\d+);)?' r'(?P' r'(?PPOINT|LINESTRING|LINEARRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON|GEOMETRYCOLLECTION)' r'[ACEGIMLONPSRUTYZ\d,\.\-\(\) ]+)$', diff --git a/django/contrib/gis/geos/tests/test_geos.py b/django/contrib/gis/geos/tests/test_geos.py index f611dd4d1a..eb13a62cb9 100644 --- a/django/contrib/gis/geos/tests/test_geos.py +++ b/django/contrib/gis/geos/tests/test_geos.py @@ -182,13 +182,14 @@ class GEOSTest(unittest.TestCase, TestDataMixin): def test01h_ewkt(self): "Testing EWKT." - srid = 32140 - for p in self.geometries.polygons: - ewkt = 'SRID=%d;%s' % (srid, p.wkt) - poly = fromstr(ewkt) - self.assertEqual(srid, poly.srid) - self.assertEqual(srid, poly.shell.srid) - self.assertEqual(srid, fromstr(poly.ewkt).srid) # Checking export + srids = (-1, 32140) + for srid in srids: + for p in self.geometries.polygons: + ewkt = 'SRID=%d;%s' % (srid, p.wkt) + poly = fromstr(ewkt) + self.assertEqual(srid, poly.srid) + self.assertEqual(srid, poly.shell.srid) + self.assertEqual(srid, fromstr(poly.ewkt).srid) # Checking export def test01i_json(self): "Testing GeoJSON input/output (via GDAL)."