Commits

megaman821  committed d4b5638

validate size querystring

  • Participants
  • Parent commits c38da99

Comments (0)

Files changed (2)

File resizer/__init__.py

 __version_info__ = {
     'major': 0,
     'minor': 1,
-    'micro': 0,
+    'micro': 1,
     'releaselevel': 'alpha',
-    'serial': 2
+    'serial': 3
 }
 
 def get_version(short=False):

File resizer/views.py

 from django.core.files.storage import default_storage
 from easy_thumbnails.files import get_thumbnailer
 from easy_thumbnails.exceptions import InvalidImageFormatError
+import re
+
+
+SIZE_RE = re.compile(r'^(\d+),(\d+)$')
 
 
 def resize(request, path):
     thumbnail_opts = {}
     if 'size' in request.GET:
-        try:
+        if SIZE_RE.match(request.GET['size']):
             thumbnail_opts['size'] = map(int, request.GET['size'].split(','))
             if 'crop' in request.GET:
                 thumbnail_opts['crop'] = request.GET['crop']
-        except ValueError:
+        else:
             return HttpResponseBadRequest(u'Size must be expressed in the format "size=[integer],[integer]"')
     else:
         return HttpResponsePermanentRedirect(default_storage.url(path))