Django

Code

Changeset 9392

Show
Ignore:
Timestamp:
11/11/08 11:21:43 (2 months ago)
Author:
jbronn
Message:

Fixed #9566 -- made GeoJSON regex more robust.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/contrib/gis/gdal/geometries.py

    r9237 r9392  
    6262hex_regex = re.compile(r'^[0-9A-F]+$', re.I) 
    6363wkt_regex = re.compile(r'^(?P<type>POINT|LINESTRING|LINEARRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON|GEOMETRYCOLLECTION)[ACEGIMLONPSRUTY\d,\.\-\(\) ]+$', re.I) 
    64 json_regex = re.compile(r'^\{[\s\w,\-\.\"\'\:\[\]]+\}$') 
     64json_regex = re.compile(r'^(\s+)?\{[\s\w,\[\]\{\}\-\."\':]+\}(\s+)?$') 
    6565 
    6666#### OGRGeometry Class #### 
  • django/trunk/django/contrib/gis/geos/base.py

    r8219 r9392  
    2222try: 
    2323    from django.contrib.gis.gdal import OGRGeometry, SpatialReference, GEOJSON 
     24    from django.contrib.gis.gdal.geometries import json_regex 
    2425    HAS_GDAL = True 
    2526except: 
     
    3132hex_regex = re.compile(r'^[0-9A-F]+$', re.I) 
    3233wkt_regex = re.compile(r'^(SRID=(?P<srid>\d+);)?(?P<wkt>(POINT|LINESTRING|LINEARRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON|GEOMETRYCOLLECTION)[ACEGIMLONPSRUTY\d,\.\-\(\) ]+)$', re.I) 
    33 json_regex = re.compile(r'^\{.+\}$') 
    3434 
    3535class GEOSGeometry(object): 
  • django/trunk/django/contrib/gis/tests/geometries.py

    r8219 r9392  
    155155              TestGeom('POLYGON((0 0, -10 0, -10 -10, 0 -10, 0 0))', json='{ "type": "Polygon", "coordinates": [ [ [ 0.000000, 0.000000 ], [ -10.000000, 0.000000 ], [ -10.000000, -10.000000 ], [ 0.000000, -10.000000 ], [ 0.000000, 0.000000 ] ] ] }'), 
    156156              TestGeom('MULTIPOLYGON(((102 2, 103 2, 103 3, 102 3, 102 2)), ((100.0 0.0, 101.0 0.0, 101.0 1.0, 100.0 1.0, 100.0 0.0), (100.2 0.2, 100.8 0.2, 100.8 0.8, 100.2 0.8, 100.2 0.2)))', json='{ "type": "MultiPolygon", "coordinates": [ [ [ [ 102.000000, 2.000000 ], [ 103.000000, 2.000000 ], [ 103.000000, 3.000000 ], [ 102.000000, 3.000000 ], [ 102.000000, 2.000000 ] ] ], [ [ [ 100.000000, 0.000000 ], [ 101.000000, 0.000000 ], [ 101.000000, 1.000000 ], [ 100.000000, 1.000000 ], [ 100.000000, 0.000000 ] ], [ [ 100.200000, 0.200000 ], [ 100.800000, 0.200000 ], [ 100.800000, 0.800000 ], [ 100.200000, 0.800000 ], [ 100.200000, 0.200000 ] ] ] ] }'), 
     157              TestGeom('GEOMETRYCOLLECTION(POINT(100 0),LINESTRING(101.0 0.0, 102.0 1.0))', 
     158                       json='{ "type": "GeometryCollection", "geometries": [ { "type": "Point", "coordinates": [ 100.000000, 0.000000 ] }, { "type": "LineString", "coordinates": [ [ 101.000000, 0.000000 ], [ 102.000000, 1.000000 ] ] } ] }', 
     159                       ), 
     160              TestGeom('MULTILINESTRING((100.0 0.0, 101.0 1.0),(102.0 2.0, 103.0 3.0))', 
     161                       json=""" 
     162 
     163{ "type": "MultiLineString", 
     164  "coordinates": [ 
     165      [ [100.0, 0.0], [101.0, 1.0] ], 
     166      [ [102.0, 2.0], [103.0, 3.0] ] 
     167    ] 
     168  } 
     169 
     170""", 
     171                       not_equal=True, 
     172                       ), 
    157173              ) 
  • django/trunk/django/contrib/gis/tests/test_gdal_geom.py

    r8219 r9392  
    8080        for g in json_geoms: 
    8181            geom = OGRGeometry(g.wkt) 
    82             self.assertEqual(g.json, geom.json) 
    83             self.assertEqual(g.json, geom.geojson) 
     82            if not hasattr(g, 'not_equal'): 
     83                self.assertEqual(g.json, geom.json) 
     84                self.assertEqual(g.json, geom.geojson) 
    8485            self.assertEqual(OGRGeometry(g.wkt), OGRGeometry(geom.json)) 
    8586 
  • django/trunk/django/contrib/gis/tests/test_geos.py

    r8219 r9392  
    103103        for g in json_geoms: 
    104104            geom = GEOSGeometry(g.wkt) 
    105             self.assertEqual(g.json, geom.json) 
    106             self.assertEqual(g.json, geom.geojson) 
     105            if not hasattr(g, 'not_equal'): 
     106                self.assertEqual(g.json, geom.json) 
     107                self.assertEqual(g.json, geom.geojson) 
    107108            self.assertEqual(GEOSGeometry(g.wkt), GEOSGeometry(geom.json)) 
    108109