David Beitey avatar David Beitey committed a8d0eb1

Ensure coerce_string_conf coerces the sign of an integer.

Comments (0)

Files changed (3)


     .. change::
         :tags: bug
+      The :func:`.util.coerce_string_conf` method now correctly coerces
+      negative integers and those with a leading + sign. This previously
+      prevented configuring a :class:`.CacheRegion` with an ``expiration_time``
+      of ``'-1'``. Courtesy David Beitey.
+    .. change::
+        :tags: bug
       The ``refresh()`` method on :meth:`.CacheRegion.get_or_create_multi`
       now supports the ``asdict`` flag.
       ``to_str``, defaults to ``str()``.  Can be replaced with ``unicode()``
       or other functions to support caching of functions that
       accept non-unicode arguments.  Initial patch courtesy Lx Yu.
     .. change::
         :tags: feature


         v = v.strip()
-        if re.match(r'^\d+$', v):
+        if re.match(r'^[-+]?\d+$', v):
             result[k] = int(v)
         elif v.lower() in ('false', 'true'):
             result[k] = v.lower() == 'true'


+from unittest import TestCase
+from dogpile.cache import util
+class UtilsTest(TestCase):
+    """ Test the relevant utils functionality.
+    """
+    def test_coerce_string_conf(self):
+        settings = {'expiration_time': '-1'}
+        coerced = util.coerce_string_conf(settings)
+        self.assertEqual(coerced['expiration_time'], -1)
+        settings = {'expiration_time': '+1'}
+        coerced = util.coerce_string_conf(settings)
+        self.assertEqual(coerced['expiration_time'], 1)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.