Commit ba2be276 authored by Claude Paroz's avatar Claude Paroz
Browse files

[1.4.x] Fixed #20036 -- Improved GEOS version string parsing

Thanks chikiro.spam at gmail.com for the report.
parent 065caafa
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -101,8 +101,11 @@ geos_version.argtypes = None
geos_version.restype = c_char_p

# Regular expression should be able to parse version strings such as
# '3.0.0rc4-CAPI-1.3.3', '3.0.0-CAPI-1.4.1' or '3.4.0dev-CAPI-1.8.0'
version_regex = re.compile(r'^(?P<version>(?P<major>\d+)\.(?P<minor>\d+)\.(?P<subminor>\d+))((rc(?P<release_candidate>\d+))|dev)?-CAPI-(?P<capi_version>\d+\.\d+\.\d+)$')
# '3.0.0rc4-CAPI-1.3.3', '3.0.0-CAPI-1.4.1', '3.4.0dev-CAPI-1.8.0' or '3.4.0dev-CAPI-1.8.0 r0'
version_regex = re.compile(
    r'^(?P<version>(?P<major>\d+)\.(?P<minor>\d+)\.(?P<subminor>\d+))'
    r'((rc(?P<release_candidate>\d+))|dev)?-CAPI-(?P<capi_version>\d+\.\d+\.\d+)( r\d+)?$'
)
def geos_version_info():
    """
    Returns a dictionary containing the various version metadata parsed from
@@ -112,8 +115,10 @@ def geos_version_info():
    """
    ver = geos_version()
    m = version_regex.match(ver)
    if not m: raise GEOSException('Could not parse version info string "%s"' % ver)
    return dict((key, m.group(key)) for key in ('version', 'release_candidate', 'capi_version', 'major', 'minor', 'subminor'))
    if not m:
        raise GEOSException('Could not parse version info string "%s"' % ver)
    return dict((key, m.group(key)) for key in (
        'version', 'release_candidate', 'capi_version', 'major', 'minor', 'subminor'))

# Version numbers and whether or not prepared geometry support is available.
_verinfo = geos_version_info()
+10 −8
Original line number Diff line number Diff line
@@ -1050,15 +1050,17 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
        print "\nEND - expecting GEOS_NOTICE; safe to ignore.\n"

    def test28_geos_version(self):
        "Testing the GEOS version regular expression."
        """Testing the GEOS version regular expression."""
        from django.contrib.gis.geos.libgeos import version_regex
        versions = [ ('3.0.0rc4-CAPI-1.3.3', '3.0.0'),
                     ('3.0.0-CAPI-1.4.1', '3.0.0'),
                     ('3.4.0dev-CAPI-1.8.0', '3.4.0') ]
        for v, expected in versions:
            m = version_regex.match(v)
            self.assertTrue(m)
            self.assertEqual(m.group('version'), expected)
        versions = [('3.0.0rc4-CAPI-1.3.3', '3.0.0', '1.3.3'),
                    ('3.0.0-CAPI-1.4.1', '3.0.0', '1.4.1'),
                    ('3.4.0dev-CAPI-1.8.0', '3.4.0', '1.8.0'),
                    ('3.4.0dev-CAPI-1.8.0 r0', '3.4.0', '1.8.0')]
        for v_init, v_geos, v_capi in versions:
            m = version_regex.match(v_init)
            self.assertTrue(m, msg="Unable to parse the version string '%s'" % v_init)
            self.assertEqual(m.group('version'), v_geos)
            self.assertEqual(m.group('capi_version'), v_capi)


def suite():
+5 −1
Original line number Diff line number Diff line
@@ -4,10 +4,14 @@ Django 1.4.16 release notes

*Under development*

Django 1.4.16 fixes a regression in the 1.4.14 security release.
Django 1.4.16 fixes a regression in the 1.4.14 security release and a bug
preventing the use of some GEOS versions with GeoDjango.

Bugfixes
========

* Allowed inline and hidden references to admin fields
  (`#23431 <http://code.djangoproject.com/ticket/23431>`_).

* Fixed parsing of the GEOS version string
  (`#20036 <http://code.djangoproject.com/ticket/20036>`_).