Skip to content

Commit

Permalink
Fixed #18675 -- Fixed was_modified_since with floating-point mtime
Browse files Browse the repository at this point in the history
Thanks Simon Charette for the patch.
  • Loading branch information
claudep committed Sep 26, 2012
1 parent b3ee80a commit 3cbe686
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion django/views/static.py
Expand Up @@ -138,7 +138,7 @@ def was_modified_since(header=None, mtime=0, size=0):
header_len = matches.group(3) header_len = matches.group(3)
if header_len and int(header_len) != size: if header_len and int(header_len) != size:
raise ValueError raise ValueError
if mtime > header_mtime: if int(mtime) > header_mtime:
raise ValueError raise ValueError
except (AttributeError, ValueError, OverflowError): except (AttributeError, ValueError, OverflowError):
return True return True
Expand Down
2 changes: 1 addition & 1 deletion tests/regressiontests/views/tests/__init__.py
Expand Up @@ -7,4 +7,4 @@
from .i18n import JsI18NTests, I18NTests, JsI18NTestsMultiPackage from .i18n import JsI18NTests, I18NTests, JsI18NTestsMultiPackage
from .shortcuts import ShortcutTests from .shortcuts import ShortcutTests
from .specials import URLHandling from .specials import URLHandling
from .static import StaticHelperTest, StaticTests from .static import StaticHelperTest, StaticUtilsTests, StaticTests
16 changes: 15 additions & 1 deletion tests/regressiontests/views/tests/static.py
Expand Up @@ -2,11 +2,14 @@


import mimetypes import mimetypes
from os import path from os import path
import unittest


from django.conf import settings from django.conf import settings
from django.conf.urls.static import static from django.conf.urls.static import static
from django.test import TestCase
from django.http import HttpResponseNotModified from django.http import HttpResponseNotModified
from django.test import TestCase
from django.utils.http import http_date
from django.views.static import was_modified_since


from .. import urls from .. import urls
from ..urls import media_dir from ..urls import media_dir
Expand Down Expand Up @@ -105,3 +108,14 @@ def setUp(self):
def tearDown(self): def tearDown(self):
super(StaticHelperTest, self).tearDown() super(StaticHelperTest, self).tearDown()
urls.urlpatterns = self._old_views_urlpatterns urls.urlpatterns = self._old_views_urlpatterns


class StaticUtilsTests(unittest.TestCase):
def test_was_modified_since_fp(self):
"""
Test that a floating point mtime does not disturb was_modified_since.
(#18675)
"""
mtime = 1343416141.107817
header = http_date(mtime)
self.assertFalse(was_modified_since(header, mtime))

0 comments on commit 3cbe686

Please sign in to comment.