diff --git a/django/contrib/gis/gdal/tests/test_geom.py b/django/contrib/gis/gdal/tests/test_geom.py index c547135b170..65d78a17354 100644 --- a/django/contrib/gis/gdal/tests/test_geom.py +++ b/django/contrib/gis/gdal/tests/test_geom.py @@ -121,6 +121,9 @@ class OGRGeomTest(unittest.TestCase, TestDataMixin): self.assertEqual(json.loads(g.json), json.loads(geom.json)) self.assertEqual(json.loads(g.json), json.loads(geom.geojson)) self.assertEqual(OGRGeometry(g.wkt), OGRGeometry(geom.json)) + # Test input with some garbage content (but valid json) (#15529) + geom = OGRGeometry('{"type": "Point", "coordinates": [ 100.0, 0.0 ], "other": ""}') + self.assertIsInstance(geom, OGRGeometry) def test02_points(self): "Testing Point objects." diff --git a/django/contrib/gis/geometry/regex.py b/django/contrib/gis/geometry/regex.py index 22d16cb4c88..7dbcbfa4e7e 100644 --- a/django/contrib/gis/geometry/regex.py +++ b/django/contrib/gis/geometry/regex.py @@ -9,4 +9,4 @@ wkt_regex = re.compile(r'^(SRID=(?P\-?\d+);)?' r'(?PPOINT|LINESTRING|LINEARRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON|GEOMETRYCOLLECTION)' r'[ACEGIMLONPSRUTYZ\d,\.\-\(\) ]+)$', re.I) -json_regex = re.compile(r'^(\s+)?\{[\s\w,\[\]\{\}\-\."\':]+\}(\s+)?$') +json_regex = re.compile(r'^(\s+)?\{.*}(\s+)?$', re.DOTALL)